I want my navigation links to be in the middle of the parent div, vertically. How do I do that?
HTML:
<div id="nav">
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
CSS:
#nav {
background: #8DC3E9;
width: 100%;
height: 70px;
border-bottom: 2px solid #4C88BE;
}
#nav ul {
margin: 0;开发者_运维问答
}
#nav ul li {
display: inline;
font-size: 40px;
}
According to your comment to the other answer, you want them vertically aligned in the middle. Since you have a fixed height already, this should work:
#nav ul {
margin: 0;
vertical-align: middle;
line-height: 70px;
}
I would just add a 15 pixel padding to the nav div:
#nav {
background: #8DC3E9;
border-bottom: 2px solid #4C88BE;
height: 70px;
padding-bottom: 15px;
padding-top: 15px;
width: 100%;
}
Also, I would highly suggest ordering your attributes alphabetically (as I've done above) so that people can more easily find the attribute for which they are looking.
Use vertical-align: middle;
it is browser compatible.
精彩评论