如何居中ul

时间:2012-08-16 14:51:58

标签: html css

我试图在空间内水平居中ul,但无论我尝试什么,它都保持左对齐。

<nav>
    <div id="home">
    <ul id="topnav">
        <li class="home"><a href="#">home</a></li>
        <li class="products"><a href="#">products</a></li>
        <li class="support"><a href="#">support</a></li>
        <li class="wtb"><a href="#">where to buy</a></li>
        <li class="webstore"><a href="#" target="_blank">web store</a></li>
        <li class="contact"><a href="#">contact us</a></li>
        <li class="facebook"><a href="#" target="_blank"
            title="Hauppauge Computer Works">facebook</a></li>
    </ul>
    </div>
</nav>

CSS: CSS file here

1 个答案:

答案 0 :(得分:1)

ul#topnav {
    padding: 0px;
    list-style: none;
    margin-right: auto;
    margin-left: auto;
    margin-top: 0px;
    margin-bottom: 0px;
    position: relative;
    left: auto;
        width: 123px;
}