Horizontal css menu question

2019-06-14 04:19发布

I have a simple ul horizontal menu that exists within a div that is set to 10% height and 100% width. How does one center text horizontally and vertically within it?

#navlistcontainer {
    position:fixed;
    height:10%;
    bottom:0px;
    left:0px;
    right:0px;
}
#navlist li {
    display: inline;
    list-style-type: none;
}
#navlist li a {
    color:#FFF;
}

  <div id="navcontainer">
    <ul id="navlist">
        <li><a href="index.html">START</a></li>
    </ul>
  </div>

标签: html css menu
2条回答
forever°为你锁心
2楼-- · 2019-06-14 04:44

try this:

#navlist {
 text-align: center;
 display: block;
}

#navlist li {
 display: inline;
}

For vertical alignment you'd need to set the line-height of navlistcontainer equal to it's height. I'm not sure it will work with height in percentage. Consider this:

#navlistcontainer {
 height: 50px;
 line-height: 50px;
}

Here is a jsFiddle: http://jsfiddle.net/FH9sZ/

查看更多
我命由我不由天
3楼-- · 2019-06-14 05:06

You shouldn't define height as precentage. http://jsfiddle.net/zzdGx/ there you go fiddle for this.

查看更多
登录 后发表回答