html - 导航栏的边框

标签 html css navigation border

我有一个带有底部边框的相当简单的导航栏,但我想将它的两边框起来 - 但不是顶部。所以我得到一个|__________|围绕着我所有的链接,但我才刚刚开始,无论我尝试什么,似乎都与我不想要的每个链接接壤。

<nav>
    <div align="center">
    <div id="navigation">
    <ul>
       <li><a href="/">Home</a></li>
       <li><a href="/about">About</a></li>
       <li><a href="/products">Products</a></li>
       <li><a href="/news">News</a></li>
       <li><a href="/careers">Careers</a></li>
       <li><a href="contact us">Contact Us</a></li>
    </ul>
    </div><!--navigation-->
</nav>  

和CSS

nav { 
  width: 100%;
  margin:0 auto;     
}
nav ul li {
  width: 16.6%;
  float: left;
  border-bottom: 1px solid #A2A2A2;
  list-style-type: none;
  display: inline;
}

nav ul li a {
  display: block;
  width: 100%;
  text-align: center;
  padding-top: 8px;
  padding-right: 8px;
  padding-bottom: 8px;
  padding-left: 8px;
  color: #202020;
  font-family: "Myriad Pro Light";
  text-transform: uppercase;
  text-decoration: none;
  font-size: 12pt;
}
nav ul li a:hover {
  color:  #89ccca
}
nav ul{
  width: 80%;
  list-style: none;
  margin: 0;
  padding: 0;
 }

最佳答案

使用 first-childlast-child 属性并像下面那样应用它。

CSS

 nav ul li:first-child
 {
   border-left: 1px solid #A2A2A2; 
 }
 nav ul li:last-child
 {
   border-right: 1px solid #A2A2A2; 
 }

FIDDLE DEMO

关于html - 导航栏的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28850534/

相关文章:

html - 流出th的div文字

html - 如何链接外部 css 来覆盖居中元素的引导 css?

html - 缓存 list 在使用跨域引用和 SSL 的 safari 中不起作用

drupal - 如何让菜单面包屑出现在 Drupal 7 的导航栏中?

jquery - 手机中的谷歌重力功能

javascript - 如何使 Bootstrap 模式宽度适应包含的图像

css - 固定表头右侧有一个空白区域

html - 如何使用CSS在断词中添加自动连字符

android - 同一 Activity Kotlin 中的抽屉导航和底部导航

html - MenuToggle 不会显示响应式导航栏