中心文本和导航对齐

时间:2014-11-03 21:34:08

标签: html css

我有一个标题和导航,我不能将它们对齐在div的中心......我想要" Onze producten"成为标题,然后,导航菜单将在标题下对齐。 我无法弄明白我该如何做到

这就是我希望它看起来......

enter image description here

HTML:

<div class="section2">
            <div class="content2">
                <p><span style="font-size:30px; color:#fdd400">Onze producten</span></p>
                <ul id="nav2">
                    <li class="active">Particulier</li>
                    <li>Zakelijk</li>
                    <li>Alle producten ></li>
                    <div class="clearfix"></div>
                </ul>
            </div>
        </div>

CSS:

.section2
{
    position:relative;
    width:100%;
    height:700px;
    border:1px solid black;
    text-align:center;
}
.content2
{
    height: 110px;
    border:1px solid red;
}
#nav2 
{
    list-style: none outside none;
    font-size:16px;
    position:absolute;
    margin-left:14.5%;
    margin-top:-17px;
    color:#6e6e6e;
}
#nav2 li 
{
    border-bottom: 2px solid #DDDDDD;
    cursor: pointer;
    float: left;
    margin: 0;
    width:160px;
    height:50px;
    line-height:50px;
    position: relative;
    text-align:center;
}
.clearfix 
{
    clear: both;
}
#nav2 li:hover:after, #nav2 li.active:after
{
    border: 1px solid #044584;
    bottom: 0;
    content: "";
    left: 0;
    position: absolute;
    width: 160px;
}
.active
{
    color:#044584;
    font-weight: bold;
}

2 个答案:

答案 0 :(得分:0)

希望这会对你有帮助:) http://jsfiddle.net/matjazmav/hgto6qhe/3/

#nav2 
{
    list-style: none outside none;
    font-size:16px;
    margin-left:14.5%;
    margin-top:-17px;
    color:#6e6e6e;

    list-style-type: none;
    padding:0;
    margin:0;
    display:inline-block;
}

同时将高度编辑为120:

.content2
{
    height: 120px;
    border:1px solid red;
}

答案 1 :(得分:0)

使用内联块而不是浮动div

#nav2 
{
    list-style: none outside none;
    font-size:16px;
    margin-top:-17px;
    color:#6e6e6e;
}
#nav2 li 
{
    border-bottom: 2px solid #DDDDDD;
    cursor: pointer;
    display: inline-block;
    margin: 0;
    width:160px;
    height:50px;
}

http://jsfiddle.net/1sr5csbv/1/