cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              header
    .menu-container
        nav.off-canvas-menu 
            ul
                li
                    a(href="#") Tasum
                li
                    a(href="#") Aldpol
                    
                li.menu-item-has-children
                    a(href="#") Oughw
                    ul.sub-menu
                        li
                            a(href="#") Shyidra
                        li
                            a(href="#") Randel
                        li
                            a(href="#") Ia'usk
                    // /.sub-menu
                    
                li
                    a(href="#") Swaimim
            // /ul
        // /.off-canvas-menu
        
        nav.main-menu
            ul.second
                li
                    a(href="#") Smedgone
                li
                    a(href="#") Aotaliope
                    
                li.menu-item-has-children
                    a(href="#") Rothiope
                    ul.sub-menu
                        li
                            a(href="#") Delirious Lyric
                        li
                            a(href="#") Cleliopyte
                        li
                            a(href="#") Xioeleia
                    // /.sub-menu
                    
                li
                    a(href="#") Iorireto    
            // /ul
        // /.main-menu
    // /.menu-container
// /header
            
          
!
            
              // SETTINGS
//-----------

// helper
//--------

// colors
$pink: #E9B4B3;
$pale-pink: #F2E4E1;
$coal: #1D2426;
$teal: #35565D;
$grass: #8AB283;

// shortcuts
$noborder: 0 solid transparent;

// variable definitions
//----------------------
$menu-collapse: 610px;
$a_color: $pale-pink;
$a_color_hover: $pink;
$header_bg: $grass;
$off-canvas_bg: $teal;
$main_menu_bg: $coal;


// FUNCTIONS
//-----------

// squareroot
@function sqrt($r) {
    $x0: 1;
    $x1: $x0;
    @for $i from 1 through 10 {
        $x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0);
        $x0: $x1;
    }
    @return $x1;
}

// MIXINS
//--------

// equilateral triangle
@mixin triangle_eqla($sl, $dir, $c) {
    width: 0;
    height: 0;
    border-style: solid;
    
    @if $dir == right {
        border-color: transparent transparent transparent $c;
    }
    @if $dir == left {
        border-color: transparent $c transparent transparent;
    }
    @if $dir == bottom or $dir == down {
        border-color: $c transparent transparent transparent;
    }
    @if $dir == top or $dir == up {
        border-color: transparent transparent $c transparent;
    }
    @if $dir == right or $dir == left {
        border-width: ($sl/2) (sqrt(3)*($sl/2));
    }
    @if $dir == top or $dir == down or $dir == bottom or $dir == up {
        border-width: (sqrt(3)*($sl/2)) ($sl/2);
    }
}

// flexbox
@mixin flexbox($direction, $wrap, $justify, $align) {
    display: flex;
    flex-direction: $direction;
    flex-wrap: $wrap;
    justify-content: $justify;
    align-items: $align;
}

// STYLING
//---------

// basic styles
body {
    font: {
        size: 16px;
        weight: 400;
        family: Roboto;
    }
    line-height: 1.5;
}

a {
    color: $a_color;
    text-decoration: none;
    &:hover {
        color: $a_color_hover;
        cursor: pointer;
    }
}

// main style
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: $header_bg;
    line-height: 2;
    
    @media screen and (max-width: $menu-collapse){
        @include flexbox(row, wrap, center, center);
    }
        
    // toggle link styling
    .toggle {
        @extend a;
        padding: 6px;
    }
    
    .toggle-link-close {
        position: absolute;
        top: 0;
        right: 0;
    }
    
    .toggle-link {
        @media screen and (min-width: $menu-collapse + 1) {
            display: none;
        }
    }
    
    .toggle-link-off-canvas {
        @media screen and (max-width: $menu-collapse) {
            display: none;
        }
    }
}

// menu container, styles will be applied for the responsive version especially
.menu-container {
    @media screen and (max-width: $menu-collapse) {
        z-index: 100;
        position: fixed;
        top: 0;
        left: -300px;
        height: 100%;
        overflow-y: auto;
        background: $off-canvas_bg;
        width: 300px;
        box-sizing: border-box;
        transition: .3s all ease;
        transform: translate(0, 0);

        &.active {
            transform: translate(300px, 0);
        }
    }
    
    // sub menu styles, are the same as with the off-canvas styling
    .sub-menu {
        border-top: 1px solid rgba($coal, .5);
        border-bottom: 1px solid rgba($coal, .5);
        background: lighten($off-canvas_bg, 5%);
        display: none;
        
        li {
            a {
                box-sizing: border-box;
                @media screen and (max-width: $menu-collapse) {
                    padding-left: 25px;
                }
            }
        }
    }
    
    // clickable triangle to toggle sub menu visibility
    .parent {
        @include flexbox(row, wrap, flex-start, center);
        
        .submenu-opener {
            font-size: 0;
            position: relative;
            width: 20px;
            height: 20px;
            transition: .6s all ease;

            @media screen and (max-width: $menu-collapse) {
                margin-left: 20px;
            }

            @media screen and (min-width: $menu-collapse + 1) {
                margin-left: 5px;
            }
            
            &.sub-menu-is-open {
                transform: rotate(-180deg);
            }
            
            &:after {
                content: '';
                @include triangle_eqla(10px, down, $a_color);
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -20%);
                transition: .3s all ease;
            }
            
            &:hover {
                cursor: pointer;
            
                &:after {
                    border-color: $a_color_hover transparent transparent transparent;
                }
            }
        }
    }
}

// off-canvas navigation
.off-canvas-menu {
    line-height: 2.5;
    
    @media screen and (min-width: $menu-collapse + 1) {
        z-index: 100;
        position: fixed;
        top: 0;
        left: -300px;
        height: 100%;
        overflow-y: auto;
        background: $off-canvas_bg;
        width: 300px;
        box-sizing: border-box;
        transition: .3s all ease;
        transform: translate(0, 0);

        &.active {
            transform: translate(300px, 0);
        }        
    }
    
    a {
        padding: 0 10px;
    }
}

// main menu for responsive and full version
.main-menu {
    @media screen and (max-width: $menu-collapse) {
        border-top: 1px solid darken($off-canvas_bg, 5%);
        line-height: 2.5;

        a {
            padding: 0 10px;
        }
    }
    
    @media screen and (min-width: $menu-collapse + 1) {
        position: fixed;
        width: 100%;
        left: 0;
        right: 0;
        background: $main_menu_bg;
        @include flexbox(row, wrap, space-between, center);
       
        ul {
            @include flexbox(row, wrap, flex-start, center);
        
            li {
                padding: 10px;
            }
        }

        .sub-menu {
            top: 100%;
            position: absolute;
            background: lighten($main_menu_bg, 5%);
        }
    }    
}
            
          
!
            
              $(document).ready(function() {
    var offCanvasToggle = 'toggle-link-off-canvas',
        mainToggle = 'toggle-link',
        close = 'toggle-link-close';

    // add toggle links 
    $('header').prepend('<span class="toggle ' + mainToggle + '">Menu</span>');
    $('.menu-container').prepend('<span class="toggle ' + mainToggle + ' ' + close + '">close</span>');
    $('.off-canvas-menu').prepend('<span class="toggle ' + offCanvasToggle + ' ' + close + '">close</span>');
    $('.main-menu').prepend('<ul class="first"><li><span class="toggle ' + offCanvasToggle + '">Menu Off-Canvas</span></li></ul>');

    // click functions for toggle links to toggle active classes on off-canvas
    $('header .toggle-link').click(function() {
        $('.menu-container').toggleClass('active');
    });

    $('header .toggle-link-off-canvas').click(function() {
        $('.off-canvas-menu').toggleClass('active');
    });

    // add Element for caret to toggle sub-menus
    $('.menu-item-has-children > a').wrap('<span class="parent"></span>');
    $('.menu-container .parent').append('<span class="submenu-opener">open submenu</span>');

    // toggling submenus
    $('.menu-container .submenu-opener').click(function() {
        $(this).toggleClass('sub-menu-is-open');
        $(this).parent().next('.sub-menu').slideToggle();
    });
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console