简体   繁体   English

在水平导航栏中将左浮动元素居中?

[英]Centering left-floated elements within horizontal navbar?

So I've got this navbar, which you can see here-- 所以我有这个导航栏,您可以在这里看到-

http://codepen.io/anon/pen/FJGvg/ http://codepen.io/anon/pen/FJGvg/

I'm trying to evenly space the elements within the navbar, and I cannot get it to work for the life of me. 我正在尝试在导航栏中均匀分配元素,但我无法让它在我的生命中发挥作用。 I have tried many things. 我已经尝试了很多东西。 Here is the code: 这是代码:

<ul id="menu">
    <li><a>Test</a></li>
    <li><a>Test Different Length </a></li>
    <li><a>Test Again</a></li>
    <li><a>Test23</a></li>
</ul>

#menu {
    width: 50%;
    min-width: 700px;
    margin: auto;
    margin-top: 10px;
    padding: 10px 0 0 0;
    list-style: none;
    text-align: center;
    background-color: #111;
    background-image: linear-gradient(#444, #111);
    border-radius: 18px;
   /* box-shadow: 0 2px 1px #9c9c9c;*/
}

#menu li {
    display: inline;
    margin-left: auto;
    width: 25%;
    float: left;
    padding: 0 0 10px 0;
    position: relative;
}

#menu a {
    float: left;
    height: 25px;
    padding: 0 25px;
    color: #999;
    text-transform: uppercase;
    font: bold 12px/25px Arial, Helvetica;
    text-decoration: none;
    text-shadow: 0 1px 0 #000;
}

#menu li:hover > a {
    color: #fafafa;
}

/* Clear floated elements */
#menu:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
}
#menu {
    width: 50%;
    min-width: 700px;
    margin: 10px auto 0 auto;
    padding: 5px 0;
    list-style: none;
    text-align: center;
    background-color: #111;
    background-image: linear-gradient(#444, #111);
    border-radius: 18px;
   /* box-shadow: 0 2px 1px #9c9c9c;*/
}

#menu li {
    display: inline-block;
    width: 23%;   
    position: relative;
    padding:0;
}

#menu a {
    height: 25px;
    color: #999;
    text-transform: uppercase;
    font: bold 12px/25px Arial, Helvetica;
    text-decoration: none;
    text-shadow: 0 1px 0 #000;
}

#menu li:hover > a {
    color: #fafafa;
}

/* Clear floated elements */
#menu:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM