See code, below code is my question ;).
HTML:
<div class="header">
<ul>
<li><a href="#">Domov</a></li>
<li><a href="#">O nás</a></li>
<li><a href="#">Služby</a></li>
<li><a href="#">Kontakt</a></li>
</ul>
</div>
CSS:
.header {
width: 1000px;
margin: auto;
margin-top: 8px;
}
.header ul {
list-style-type: none;
background: #363b40;
}
.header ul li {
float: left;
}
.header a {
color: #a3a7a6;
text-decoration: none;
}
My question is why DIV background hide when I add "float: left" to .header ul li. Any solution please?
The reason this is occurring is because the
ul
is collapsing, as it doesn't have any defined dimensions. When you float the children elements, it takes them out of the flow of the document. The same thing happens when you set their position to absolute.You have a few options..
Set
overflow:hidden
on the parent, forcing it to contain the children.jsFiddle example
...or setting a defined height on the
ul
.jsFiddle example
add the class
clearfix
toheader
and the following code to your css`