开发者

Centering horizontal UL

开发者 https://www.devze.com 2023-02-25 04:29 出处:网络
I can\'t seem to get my UL to center in its DIV. <div id=\"sitenavdiv\"> <ul id=\"sitenav\">

I can't seem to get my UL to center in its 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>

I have the following 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.abou开发者_开发百科t{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;}

I'm sure it's something simple, but I can't seem to get the combination right.


Your rule for ul#sitenav should be:

ul#sitenav {width: 231px; margin: 0 auto; display: block; }

Note the display: block;, and 231px instead of just 231.

(See and edit, with some extra colors, http://jsfiddle.net/eRRjy/)

0

精彩评论

暂无评论...
验证码 换一张
取 消