我似乎无法让我的UL以其DIV为中心。
<div id="sitenavdiv">
<ul id="sitenav">
<li class="about"><a href="#" title=""><img src="images/about-link.png" alt="about"></a></li>
<li class="portfolio"><a href="#" title=""><img src="images/portfolio-link.png" alt="portfolio"></a></li>
<li class="contact"><a href="#" title=""><img src="images/contact-link.png" alt="contact"></a></li>
</ul>
</div>
我有以下CSS:
#sitenavdiv {padding-top: 30px; width: 620px; position: relative; float: left; text-align:center;}
ul#sitenav {width: 231; margin: 0 auto; display: inline;}
ul#sitenav li.about{width: 64px; height: 31px; display: block; float: left; overflow: hidden;}
ul#sitenav li.about a{width: 64px; height: 31px; display: block;}
ul#sitenav li.about a:hover{width: 64px; height: 31px; display: block; margin-top:-31px;}
ul#sitenav li.portfolio{width: 88px; height: 31px; display: block; float: left; overflow: hidden}
ul#sitenav li.portfolio a{width: 88px; height: 31px; display: block;}
ul#sitenav li.portfolio a:hover{width: 88px; height: 31px; display: block; margin-top:-31px;}
ul#sitenav li.contact{width: 79px; height: 31px; display: block; float: left; overflow: hidden}
ul#sitenav li.contact a{width: 79px; height: 31px; display: block;}
ul#sitenav li.contact a:hover{width: 79px; height: 31px; display: block; margin-top:-31px;}
我确信这很简单,但我似乎无法正确组合。
答案 0 :(得分:2)
ul#sitenav
的规则应为:
ul#sitenav {width: 231px; margin: 0 auto; display: block; }
请注意display: block;
和231px
,而不只是231
。
(查看并编辑,加上一些额外的颜色,http://jsfiddle.net/eRRjy/)