I'm trying to create a simple menu with floated nested lists. The idea is to show all nested lists at once (like a mega menu) but I keep getting unwanted white space due to the floated elements clearing the right floated nested list.
JSFiddle is here: https://jsfiddle.net/agenturallison/mrf5e820/21/
The issue is the space above the "Level2 THIS" li element which should not be there.
How can I force the floated LI element to float up without clearing any content on the right?
HTML code:
ul {
list-style:none;
margin: 0;
padding: 0;
}
li {
margin: 0;
padding: 0;
}
a {
color: #fff;
}
#container {
width: 400px;
}
#container li {
width: 200px;
float: left;
background: blue;
}
#container .level3 {
background: green;
height: 100px;
overflow: visible;
}
#container .level3 li {
background: black;
opacity: 0.5;
}
<ul id="container">
<li><a href="#">Level 2</a>
<ul class="level3">
<li><a href="#">Level 3</a></li>
</ul>
</li>
<li><a href="#">Level 2</a></li>
<li><a href="#">Level 2</a></li>
<li><a href="#">Level 2</a>
<ul class="level3">
<li><a href="#">Level 3</a></li>
</ul>
</li>
<li><a href="#">Level 2 THIS</a></li>
<li><a href="#">Level 2</a>
<ul class="level3">
<li><a href="#">Level 3</a></li>
</ul>
</li>
</ul>
An example of how I'd like it visually to look like is like this
And this is the space I want to get rid off: JSFiddle screenshot