Consider the following simple menu markup (automatically generated, and I don't have much control over it):
.menu { width: 500px; height: 20px; list-style: none; padding: 0; margin: 0; } li { float: left; position: relative; margin-right: 30px; } ul li .submenu { position: absolute; left: 0; display: none; padding: 0; margin: 0; list-style: none; width: 100px; } ul li:hover .submenu { display: block; }
<ul class="menu"> <li>Lorem ipsum</li> <li>Submenu <ul class="submenu"> <li>Sub item 1</li> <li>Sub item 2</li> </ul> </li> <li>consectetur</li> <li>adipiscing elit</li> <li>Aliquam elit nisi</li> <li>pharetra quis</li> <li>nulla eget</li> </ul>
In the above code, the menu has a fixed width, but it has more elements than can be in this width, so the rest of the elements will be displayed in the second line. I want to display only elements that can fit on the first line, and want to hide the rest.
For this purpose, I want to specify a height for the menu. I use this CSS for the menu:
.menu { width: 500px; height: 20px; overflow: hidden; }
The problem is that the above css also hides .submenu elements. Please check out the demo to understand the problem.

Demo: http://jsfiddle.net/Lgyg2a4r/
source share