根據下面的代碼,有人可以幫助我將「ul」垂直和水平居中放在「div」中嗎?垂直和水平方向的中心ul div
非常感謝!
<div id="nav">
<ul>
<li><a class="top" href="#top"><span></span></a></li>
<li><a class="bottom" href="#bottom"><span></span></a></li>
<li><a>Link 1</a></li>
<li><a>Link 2</a></li>
</ul>
</div>
CSS
#nav {
height:35px;
border-bottom:1px solid #ddd;
position:fixed;
top:0px;
left:0px;
right:0px;
background:#fff url(../images/navigation/nav.png) repeat-x center left;
z-index:999999;
}
#nav ul {
list-style:none;
margin:auto;
float:left;
padding:0;
display: block;
}
#nav ul li {
display:inline;
float:left;
margin:0px 2px;
}
#nav a {
font-size:13px;
font-weight:bold;
float:left;
padding: 2px 4px;
color:#999;
text-decoration: none;
border:1px solid #ccc;
cursor: pointer;
background:transparent url(../images/navigation/overlay.png) repeat-x center left;
height:16px;
line-height:16px;
}
#nav a:hover {
background:#D9D9DA none;
color: #fff;
}
#nav a.top span, #nav a.bottom span {
float:left;
width:16px;
height:16px;
}
#nav a.top span {
background:transparent url(../images/navigation/top.png) no-repeat center center;
}
#nav a.bottom span {
background:transparent url(../images/navigation/bottom.png) no-repeat center center;
}
您不能將「float:left」和「margin:auto」組合起來,它們只會在左側結束,並在「#nav ul」中進行測試以替換「float:left」whit「width:200px; border:solid red 1px;「然後它的居中 –