0

http://cssdesk.com/sv2Wq

我正在尝试垂直对齐相应的文本<li>。我构建它的方式似乎不太可能,因为盒子本身就是链接。

这是做一个简单导航栏的标准方法,对吧?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title>
</title>
</head>
<body>
<div id="wrapper">
<div id="navbar">
<ul>
<li><a href="home.php">Home</a></li>
<li><a href="news.php">News</a></li>
<li><a href="roster.php">Roster</a></li>
<li><a href="forums.php">Forums</a></li>
<li><a href="contact.php">Contact</a></li>
</ul> 
</div>
</div>
</body>
</html>

--

body, div, dl, dt, dd, ul, ol, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input,textarea, p, blockquote, th, td {
margin: 0;
padding: 0;
}

body {
background-image:url("images/gradients/background_gradient.png");
}

#wrapper {
margin: auto;
min-height: 1152px;
width: 1536px;
}

#navbar {
border: 1px solid red;
height: 200px;
width: 100%;
font-size: 2em;
margin: 0;
}

#navbar a {
text-decoration: none;
}

#navbar ul {
display: block;
list-style-type: none;
}

#navbar ul li a {
float: left;
display: block;
height: 200px;
width: 20%;
text-align: center;
letter-spacing: -0.5px;
}

#navbar ul li :hover{
background-color: white;
}
4

3 回答 3

0

这是可能的 - 只需添加line-height

#navbar ul li a {
    display: block;
    float: left;
    height: 200px;
    letter-spacing: -0.5px;
    line-height: 200px; /* this */
    text-align: center;
    width: 20%;
}
于 2012-08-29T19:12:24.557 回答
0

将锚点的行高设置为与列表元素的高度相同的值。

编辑:太慢了:)

哦,顺便说一句:只要您的链接在一行上,它就可以工作。

于 2012-08-29T19:13:04.163 回答
0

使用它在 html 框中垂直居中。对我来说很棒。确保它在链接css中。

display:table-cell;
vertical-align:middle;

这是在css中...

#navbar ul li a {
float: left;
height: 200px;
width: 20%;
text-align: center;
letter-spacing: -0.5px;
    display:table-cell;
    vertical-align:middle;
}
于 2012-08-29T19:15:01.657 回答