Consider following simple menu markup (automatically generated, and I do not have much control over it):
.menu {
width: 500px;
height: 20px;
list-style: none;
padding: 0;
margin: 0;
/* overflow: hidden ... problem */
}
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 items than can fit in that width, so the rest of the items will go on the second line. I want to display only the items which can fit in first line, and want to hide the rest of them.
For that purpose I want to specify the height for the menu. I am using this CSS for the menu:
.menu {
width: 500px;
height: 20px;
overflow: hidden; /* problem */
}
Problem is that The above css hides the .submenu items too. Please see the demo to understand the problem.
