繁体   English   中英

CSS导航栏环绕

[英]CSS Nav Bar wrapping around

我正在尝试创建自己的CSS菜单栏,我学到了很多东西。 不幸的是,我被困在这一块上,我不知道该如何解决。 我的菜单栏太长了,因此我使用换行符将每个菜单元素包装起来,但是它不允许我的菜单在菜单栏上运行。 你能告诉我我在这里想念什么吗?

<div id="menucontainer">
<ol id="navlinks">
  <li><a href="#">COMPANY<br />OVERVIEW</a></li>    
  <li><a href="#">CLIENTS<br />TESTIMONIALS</a></li>
  <li><a href="#">ACCREDITATION<br />SERVICES</a></li>
  <li><a href="#">LEGAL<br />SUPPORT</a></li>
  <li>TRAINING</li>
  <li><a href="#">CONSULTING<br />SERVICES</a></li>
  <li><a href="#">FREE<br />POLICY CENTER</a></li>
  <li><a href="#">IN THE NEWS</a></li>
  <li><a href="#">STRATEGIC<br />PARTNERS</a></li>
</ol>
</div>

CSS代码:

   /* We set the width and color of the background for a menu wrapper. */
   #menucontainer{width: 1021px; height: 61px; background-color:#0C318C; margin: auto; padding-top:5px;}

   /* We target the top of the order list and remove the list properties. */
   #navlinks li {display: inline; list-style: none;}

   /* This line sets the font style of the bullet menu */ 
   ol{font-size: 12px; font-family: 'Tinos', serif;line-height: 18px;} 

   /* We target the li items with and without a hyper link and color the font white. */ 
   li, li a {text-decoration: none; color: white;}

我把它放在JFiddle上,您可以在这里找到它: http : //jsfiddle.net/L4sTB/

谢谢,弗兰克·G。

检查这个小提琴

我对以下CSS规则进行了更改。

#navlinks li {
    display: inline-block; /* to display the menu items as blocks in same line */
    list-style: none;
    text-align: center; /* center align the text within the block */
    width: 10%; /* set each block a width */
    vertical-align: middle; /* align the contents to middle vertically */
}

您可以将display:inline-blockli元素,它将跨越导航栏的宽度: http : //jsfiddle.net/shaunp/L4sTB/3/

这是您想要的效果吗?

该列表应为inline-block 我为每个文本添加了居中对齐文本和边框。

#navlinks li {display: inline-block; list-style: none;text-align:center;border: 1px solid white;}

暂无
暂无

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

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