簡體   English   中英

在水平導航欄中將左浮動元素居中?

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

所以我有這個導航欄,您可以在這里看到-

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

我正在嘗試在導航欄中均勻分配元素,但我無法讓它在我的生命中發揮作用。 我已經嘗試了很多東西。 這是代碼:

<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