【发布时间】:2012-04-21 09:10:47
【问题描述】:
我已经做了一个功能性的 CSS 导航栏,除了一些丑陋的 CSS 副作用 --
我试图将每个列表块中的文本垂直居中,而vertical-align: middle 不起作用。相反,我使用padding-top: 13px,但这会呈现没有列表元素其余部分的background-color 的填充区域,并且链接的display: inline block 样式确实不扩展到填充地区要么! (a:hover 仅影响填充下方的区域)
那么如何在没有这些 CSS 问题的情况下将列表元素中的文本垂直居中?
这是相关的 CSS:
/* header section */
#header
{
padding-left: 115px;
margin-bottom: 10px;
}
#main-menu
{
list-style-type: none;
}
#main-menu li
{
border: 1px solid black;
text-align: center;
padding-top: 13px;
color: #666;
font-family: "Lucida Console";
font-variant: small-caps;
letter-spacing: 2px;
/* for block layout */
display: -moz-inline-box; /* for firefox */
display: inline-block;
width: 153px;
height: 32px;
}
#main-menu a:link, a:visited
{
display: -moz-inline-box; /* for firefox */
display: inline-block;
width: 100%;
height: 100%;
background-color: #eee;
}
#main-menu a:hover, a:active
{
background-color: #bbb;
}<br /><br />
...这里是相关的 HTML:
<!-- header section -->
<div id = "header">
<ul id = "main-menu">
<!-- no spaces between list elements when all on the same line! -->
<li><a href = "home.html" title = "home">home</a></li><li><a href = "about.html" title = "about">about</a></li><li><a href = "cart.html" title = "shopping cart">cart</a></li><li><a href = "login.html" title = "log in">login</a></li><li><a href = "createAccount.html" title = "create a new account">sign up</a></li>
</ul>
</div> <!-- end of header section -->
【问题讨论】:
标签: css center padding vertical-alignment navigationbar