Nav Isn与Parent Div垂直对齐

时间:2014-05-08 19:03:04

标签: html css alignment nav

如此截图所示......

enter image description here

...我有一个红色导航栏,它不是垂直居中的,它的父div(灰色条)。我已经尝试了overflow:hidden,但这只是隐藏了问题。

HTML:

  <div class="menu">
  <nav>
    <ul>
      <li> <a href="#"> <span>Home</span> </a> </li>
      <li> <a href="#"> <span>About</span> </a> </li>
      <li> <a href="#"> <span>Portfolio</span> </a> </li>
      <li> <a href="#"> <span>Contact</span> </a> </li>
    </ul>
  </nav>

</div>

CSS:

.menu {
    position: absolute;
    min-height: 0%; /*RESET*/
    bottom: 0;
    width: 100%;
    height: 70px;
    background: #3e3e3e;
    z-index: 9999;

}
nav {
    height:100%;
    width: 700px;
    margin: 0 auto;
    background-color:#F00;
}
nav ul {
    padding-bottom:20px;
    line-height:0;
    list-style: none;
    position: relative;
}
nav ul li {
    float: left;
    margin: 0 20px 0 0;
}
nav ul li a {
    display: block;
    width: 50;
    height: 50px;
    background-color:#006;
}

3 个答案:

答案 0 :(得分:1)

试试这个。 http://jsfiddle.net/4gf32/2/

.menu {
    text-align: center;
}

nav {
    display: inline-block;
}

答案 1 :(得分:1)

您的nav ul需要display: inline-block; - 看看: http://jsfiddle.net/Wt3HE/

答案 2 :(得分:0)

我已将您的代码粘贴到jsfiddle并添加了一些:

body {
    margin: 0;
} 
.menu {
    position: absolute;
    min-height: 0%; /*RESET*/
    bottom: 0;
    width: 100%;
    height: 70px;
    background: #3e3e3e;
    z-index: 9999;
    text-align: center;
}
nav {
    display: inline-block;
    height:100%;
    width: 700px;
    margin: 0 auto;
    background-color:#F00;
}
nav ul {
    padding-bottom:20px;
    line-height:0;
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative;
}
nav ul li {
    float: left;
    margin: 0 20px 0 0;
}
nav ul li a {
    display: block;
    width: 50;
    height: 50px;
    background-color:#006;
}

http://jsfiddle.net/uPPY2/3/