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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <!--Made with Love by Larry Geams-->

<h1>Solution for Long Drop Down Items</h1>

<nav>
<ul class="dropdown">
        	<li class="drop"><a href="#">Really Tall Menu</a>
        		<ul class="sub_menu">
							<li><a href="#">Lorem</a></li>
							<li><a href="#">Ipsum</a></li>
							<li><a href="#">Dolor</a></li>
							<li><a href="#">Lipsum</a></li>
							<li><a href="#">Consectetur </a></li>
							<li><a href="#">Duis</a></li>
							<li><a href="#">Sed</a></li>
							<li><a href="#">Natus</a></li>
							<li><a href="#">Excepteur</a></li>
							<li><a href="#">Voluptas</a></li>
							<li><a href="#">Voluptate</a></li>
							<li><a href="#">Malorum</a></li>
							<li><a href="#">Bonorum</a></li>
							<li><a href="#">Nemo</a></li>
							<li><a href="#">Quisquam</a></li>
							<li><a href="#">Adipisci </a></li>
							<li><a href="#">Excepteur</a></li>
							<li><a href="#">Consectetur </a></li>
							<li><a href="#">Duis</a></li>
							<li><a href="#">Voluptate</a></li>
							<li><a href="#">Ipsum</a></li>
							<li><a href="#">Dolor</a></li>
							<li><a href="#">Lipsum</a></li>
        		</ul>
        	</li>
        	<li class="drop"><a href="#">Kinda Tall Menu</a>
        		<ul class="sub_menu">
        			<li><a href="#">Lorem</a></li>
							<li><a href="#">Ipsum</a></li>
							<li><a href="#">Dolor</a></li>
							<li><a href="#">Lipsum</a></li>
							<li><a href="#">Consectetur </a></li>
							<li><a href="#">Duis</a></li>
							<li><a href="#">Sed</a></li>
							<li><a href="#">Natus</a></li>
							<li><a href="#">Excepteur</a></li>
							<li><a href="#">Voluptas</a></li>
							<li><a href="#">Voluptate</a></li>
							<li><a href="#">Malorum</a></li>
							<li><a href="#">Bonorum</a></li>
							<li><a href="#">Nemo</a></li>
							<li><a href="#">Quisquam</a></li>
							
        		</ul>
        	</li>
        	<li class="drop"><a href="#">Average Menu</a>
        		<ul class="sub_menu">
        			<li><a href="#">Lorem</a></li>
							<li><a href="#">Ipsum</a></li>
							<li><a href="#">Dolor</a></li>
							<li><a href="#">Lipsum</a></li>
							<li><a href="#">Consectetur </a></li>
        		</ul>
        	</li>
        	<li><a href="#">No Menu</a>
        	</li>
        </ul>
</nav> 
            
          
!
            
              body{
  margin: 0px;
  padding: 0px;
  background: #e74c3c;
  font-family: 'Lato', sans-serif;
}

h1{
  margin: 2em 0px;
  padding: 0px;
  color: #fff;
  text-align: center;
  font-weight: 100;
  font-size: 50px;
}

nav{
  width: 750px;
  margin: 1em auto;
}

ul{
  margin: 0px;
  padding: 0px;
  list-style: none;
}

ul.dropdown{ 
  position: relative; 
  width: 100%; 
}

ul.dropdown li{ 
  font-weight: bold; 
  float: left; 
  width: 180px; 
  position: relative;
  background: #ecf0f1;
}

ul.dropdown a:hover{ 
  color: #000; 
}

ul.dropdown li a { 
  display: block; 
  padding: 20px 8px;
  color: #34495e; 
  position: relative; 
  z-index: 2000; 
  text-align: center;
  text-decoration: none;
  font-weight: 300;
}

ul.dropdown li a:hover,
ul.dropdown li a.hover{ 
  background: #3498db;
  position: relative;
  color: #fff;
}


ul.dropdown ul{ 
 display: none;
 position: absolute; 
  top: 0; 
  left: 0; 
  width: 180px; 
  z-index: 1000;
}

ul.dropdown ul li { 
  font-weight: normal; 
  background: #f6f6f6; 
  color: #000; 
  border-bottom: 1px solid #ccc; 
}

ul.dropdown ul li a{ 
  display: block; 
  color: #34495e !important;
  background: #eee !important;
} 

ul.dropdown ul li a:hover{
  display: block; 
  background: #3498db !important;
  color: #fff !important;
} 

.drop > a{
  position: relative;
}

.drop > a:after{
  content:"";
  position: absolute;
  right: 10px;
  top: 40%;
  border-left: 5px solid transparent;
  border-top: 5px solid #333;
  border-right: 5px solid transparent;
  z-index: 999;
}

.drop > a:hover:after{
  content:"";
   border-left: 5px solid transparent;
  border-top: 5px solid #fff;
  border-right: 5px solid transparent;
}


            
          
!
            
              /*
* 
* Credits to https://css-tricks.com/long-dropdowns-solution/
*
*/

var maxHeight = 400;

$(function(){

    $(".dropdown > li").hover(function() {
    
         var $container = $(this),
             $list = $container.find("ul"),
             $anchor = $container.find("a"),
             height = $list.height() * 1.1,       // make sure there is enough room at the bottom
             multiplier = height / maxHeight;     // needs to move faster if list is taller
        
        // need to save height here so it can revert on mouseout            
        $container.data("origHeight", $container.height());
        
        // so it can retain it's rollover color all the while the dropdown is open
        $anchor.addClass("hover");
        
        // make sure dropdown appears directly below parent list item    
        $list
            .show()
            .css({
                paddingTop: $container.data("origHeight")
            });
        
        // don't do any animation if list shorter than max
        if (multiplier > 1) {
            $container
                .css({
                    height: maxHeight,
                    overflow: "hidden"
                })
                .mousemove(function(e) {
                    var offset = $container.offset();
                    var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
                    if (relativeY > $container.data("origHeight")) {
                        $list.css("top", -relativeY + $container.data("origHeight"));
                    };
                });
        }
        
    }, function() {
    
        var $el = $(this);
        
        // put things back to normal
        $el
            .height($(this).data("origHeight"))
            .find("ul")
            .css({ top: 0 })
            .hide()
            .end()
            .find("a")
            .removeClass("hover");
    
    });  
    
});




            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console