Reputation: 3270
I'm trying to build a navigation, and I want the bar to be the same height as the links.
It's clearly sized based on the logo, if I take out the logo, the bar disappears.
Is this possible to do without setting a static height? (I want to do this so that the buttons are perfectly centered vertically and fill the whole bar vertcally.)
html
<header><!-- header -->
<a id="logo" href="/">Logo</a>
<nav><!-- navigation -->
<ul>
<li><a href="/">Home</a></li>
<li><a href="/gallery">Gallery</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="/blog">Blog</a></li>
</ul>
</nav>
</header>
css
html,body { height:100%; }
header {
background-color: red;
}
header a {
color: #fff;
text-decoration: none;
}
header ul {
list-style-type: none;
padding: 0px;
margin: 0px;
}
header ul a{
font-size: 1.5em;
display: block;
}
Upvotes: 1
Views: 238
Reputation: 207891
Add overflow:auto
to your header:
header {
background-color: red;
overflow:auto;
}
When you float the child elements, they're removed from the flow of the document and the parent effectively collapses. Adding overflow:auto
restores the behavior you're after.
Upvotes: 2