<ul>在div容器内水平居中</ul>

时间:2014-04-16 04:21:14

标签: html css html-lists

我想将ul-list集中在div-container中。 我的代码:

<div class="subnav_wines">
    <ul>
        <li><a href="?sel_regio=4">ToBeDefined</a>
        </li>
        <li><a href="?sel_regio=2">Valpollicella</a>
        </li>
        <li><a href="?sel_regio=1">Veneto</a>
        </li>
        <li id="dd_sort" class="last"><a id="" href="#">Sorted by</a>
        </li>
    </ul>
    <div style="clear:both"></div>
</div>

CSS:

.subnav_wines {
    border-bottom: 1px solid #b58150;
    padding: 0;
    margin-bottom: 0px;
}
.subnav_wines ul {
    padding: 0;
    margin: 0;
    text-align: center;
}
.subnav_wines li {
    float:left;
    padding: 10px 25px 10px 25px;
    margin: 0;
}
.subnav_wines li.last {
    border-right: 0;
    padding: 0;
}
.subnav_wines li a {
    text-transform: uppercase;
    color: #b58150;
    text-decoration: none;
}
.subnav_wines li a:hover {
    border-bottom: 1px solid #b58150;
}
.subnav_wines li a.active {
    border-bottom: 1px solid #b58150;
}

任何人都可以帮助我吗?

感谢。

3 个答案:

答案 0 :(得分:1)

float:left的{​​{1}}正在将列表项推送到其父.subnav_wines li的左侧。尝试删除ul的{​​{1}}并添加float:left

.subnav_wines li

<强> DEMO

答案 1 :(得分:0)

将以下内容添加到您的CSS

.subnav_wines {
    text-align: center;
}
.subnav_wines ul {
    display: inline-block;
}

Demo

答案 2 :(得分:0)

您可以尝试下面的ul

代码
    .subnav_wines { border-bottom: 1px solid #b58150; padding: 0; margin-bottom: 0px; text-align:center}
    .subnav_wines ul { padding: 0; display:inline-block; }

工作示例:http://jsfiddle.net/zQTD3/