cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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.

            
              <div class="menu">
    <ul>
        <li><a href="#">Anchor 1<span></span></a>
            <ul class="sub-menu">
                <li><a href="#">Anchor</a></li>
                <li><a href="#">Anchor</a></li>
                <li><a href="#">Anchor</a></li>
            </ul>
        </li>
        <li><a href="#">Anchor 2<span></span></a>
            <ul class="sub-menu">
                <li><a href="#">Anchor</a></li>
                <li><a href="#">Anchor</a></li>
            </ul>
        </li>
        <li><a href="#">Anchor 3<span></span></a>
            <ul class="sub-menu">
                <li><a href="#">Anchor</a></li>
                <li><a href="#">Anchor</a></li>
                <li><a href="#">Anchor<span></span></a>
                    <ul class="sub-menu">
                        <li><a href="#">Anchor</a></li>
                        <li><a href="#">Anchor</a></li>
                        <li><a href="#">Anchor</a></li>
                    </ul>
                </li>
            </ul>
        </li>
        <li><a href="#">Anchor 4<span></span></a>
            <ul class="sub-menu">
                <li><a href="#">Anchor</a></li>
                <li><a href="#">Anchor</a></li>
                <li><a href="#">Anchor</a></li>
            </ul>
        </li>
    </ul>
</div>
            
          
!
            
              * {
    padding: 0;
    margin: 0;
    list-style-type: none;
    font-size: 12px;
    font-weight: bold;
    font-family: arial, sans-serif;
    text-decoration: none;
}

div.menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    background: rgba(0, 0, 0, .8);
}

/* top level and cascade */
div.menu ul li {
    margin-bottom: 1px;
    position: relative; /* For holding absolute sub menus */
}

div.menu ul li a {
    line-height: 40px;
    padding: 0 0 0 10px;
    display: block;
    background: rgba(0, 0, 0, .5);
    color: rgba(255, 255, 255, .5);
}

div.menu ul li a span {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    float: right;
    background: rgba(0, 0, 0, .5);
}

/* second and third level */
ul.sub-menu  {
    display: none;
    position: absolute;
    top: 0;
    left: 100%;
    width: 200px;
    background: rgba(0, 0, 0, .5);
}

/* utility */
/* ul li:nth-child(3) ul.sub-menu, ul li:nth-child(3) ul.sub-menu li ul.sub-sub-menu {
    display: block;
} */
ul.active {
    display: block;
}
span:before {
    content: ">"
}
span.close:before {
    content: "X"
}
            
          
!
            
              $(document).ready(function(){
  
  /*$('ul > li a span').on('click', function(e){

        e.preventDefault();
      
        hide_sub_menus();
        
        if($(this).hasClass('close')) {

            $('ul.primary li a span').removeClass('close');
            $(this).parents('li').find('> ul.sub-menu').removeClass('active');

        }
        else {
            
            $(this).addClass('close');
            $(this).parents('li').find('> ul.sub-menu').addClass('active');

        }*/
  
    $('ul > li a span').on('click', function(e){
      
      // No Defaults
      e.preventDefault();
              
      // Is Clicked <span> in open state?
      if($(this).hasClass('close')) {
        // If so...
        
        // Does trav-ing three parents up bring you to main menu
        // (if so then you are two tiers down)
        // and
        // Is first tier <span> in open state also?
        if ($(this).parents('li').parents('li').parents('.menu').hasClass('menu') && $(this).parents('li').parents('li').find('a span').hasClass('close')) {
          // If so...
          
          // Reset Menus
          hide_sub_menus();
          
          // Re-apply open state to first tier
          $(this).parents('li').parents('li').find('a span').addClass('close');
          $(this).parents('li').parents('li').find('> ul.sub-menu').addClass('active');
          
          // Close second tier
          $(this).removeClass('close');
          $(this).parents('li').find('> ul.sub-menu > li > ul.sub-menu').removeClass('active');

        }  else {
          // We're at first tier with an open menu
          
          // Reset Menus
          hide_sub_menus();
        }
      // Is Clicked <span> NOT in open state
      // and
      // Is the # of open state <spans> at least 1?
      } else if (!$(this).hasClass('close') && $('.close').length >=1 ) {
        // If so...
          
            // Are we one tier in?
            if ($(this).parents('li').find('a span').hasClass('close')) {
              
              // Reset Menus
              hide_sub_menus();
              
              // But Keep this one open
              $(this).parents('li').find('a span').addClass('close');
              $(this).parents('li').find('> ul.sub-menu').addClass('active');
            } else {
              // Reset Menus
              hide_sub_menus();
            }
        
            // Open Menu
            $(this).addClass('close');
            $(this).parents('li').find('> ul.sub-menu').addClass('active');
        } else {
          
            // Open Menu
            $(this).addClass('close');
            $(this).parents('li').find('> ul.sub-menu').addClass('active');
        }

    });
  
    $('ul').on('click', function(e){
        
        e.stopPropagation();
        
    });
  
    function hide_sub_menus(){
      
        $('ul li a span').removeClass('close');
        $('ul.sub-menu').removeClass('active');
      
    }
  
});
            
          
!
999px
Loading ..................

Console