2012-10-19 19 views
3

我有一个ul与1px的左边界以及其li儿童的2px底部边框。问题是我想保持每个li元素底部边界之间的1px空间。下面是它目前的样子:防止border-bottom“渗入”边框?

example

如何,我想它看起来:

example

正如你所看到的,一旦border-left结束时,border-bottom继续,在填充1px的差距。有没有办法来防止这种情况?

下面是相关HTML:

 <div id="mainNav"> 
      <ul> 
      <li> 
       <a href="#" class="mainNavLink">Leaderboards</a> 
      </li> 
      <li> 
       <a href="#" class="mainNavLink">Statistics</a> 
      </li> 
      <li id="mainNavSearch">Search</li> 
     </ul> 
     </div> 

而CSS:

#mainNav{ 
    width: 100%; 
    height: 35px; 
    background-color: #202020; 
    border-bottom: 1px solid #444; 
    position: relative; 
    overflow: hidden; 
} 

#mainNav ul{ 
    width: 960px; 
    height: 35px; 
    margin: 0 auto 0 auto; 
    display: block; 
    position: relative; 
} 

#mainNav ul li{ 
    float: left; 
    position: relative; 
    height: 25px; 
    padding: 10px; 
    padding-top: 8px; 
    padding-bottom: 0; 
    font-size: 17px; 
    border-left: 1px solid #444; 
    border-bottom: 2px solid #00a4ff; 
    background: -moz-linear-gradient(top, rgba(24,24,24,0) 60%, rgba(24,24,24,0.38) 90%, rgba(0,0,0,0.5) 100%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(60%,rgba(24,24,24,0)), color-stop(90%,rgba(24,24,24,0.38)), color-stop(100%,rgba(0,0,0,0.5))); 
    background: -webkit-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: -o-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: -ms-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: linear-gradient(to bottom, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00181818', endColorstr='#80000000',GradientType=0); 
} 

#mainNavSearch{ 
    border-right: 1px solid #444; 
} 
+0

你或许可以用背景属性来做到这一点。 – twodayslate

回答

0

由于我找不到防止边界泄漏的方法,而且我不希望a成为整个li元素的大小,所以我不得不插入其他div并应用border-bottompadding-left/right样式,与其:

HTML:

<div id="mainNav"> 
     <ul> 
      <li> 
       <div> 
        <a href="#" class="mainNavLink">Leaderboards</a> 
       </div> 
      </li> 
      <li> 
       <div> 
        <a href="#" class="mainNavLink">Statistics</a> 
       </div> 
      </li> 
      <li id="mainNavSearch">Search</li> <!-- I did not include a div here as I plan on changing this to a search bar later --> 
     </ul> 
    </div> 

CSS:

#mainNav{ 
    width: 100%; 
    height: 35px; 
    background-color: #202020; 
    border-bottom: 1px solid #444; 
    position: relative; 
    overflow: hidden; 
} 

#mainNav ul{ 
    width: 960px; 
    height: 35px; 
    margin: 0 auto 0 auto; 
    display: block; 
    position: relative; 
} 

#mainNav ul li{ 
    float: left; 
    position: relative; 
    height: 27px; 
    font-size: 17px; 
    border-left: 1px solid #444; 
    padding-top: 8px; 
} 
#mainNav div{ 
    display: block; 
    position: relative; 
    height: 25px; 
    padding: 0 10px 0 10px; 
    border-bottom: 2px solid #00a4ff; 
    background: -moz-linear-gradient(top, rgba(24,24,24,0) 60%, rgba(24,24,24,0.38) 90%, rgba(0,0,0,0.5) 100%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(60%,rgba(24,24,24,0)), color-stop(90%,rgba(24,24,24,0.38)), color-stop(100%,rgba(0,0,0,0.5))); 
    background: -webkit-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: -o-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: -ms-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: linear-gradient(to bottom, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00181818', endColorstr='#80000000',GradientType=0); 
} 
#mainNavSearch{ 
    border-right: 1px solid #444; 
    padding: 0 10px 0 10px; 
} 

输出:

output


如果有人知道如何做到这一点没有额外 div,不实施样式的 a标签,请不要共享。

0

风格内a元素

现场演示可以在这里看到:http://jsbin.com/welcome/36341

* { margin: 0; padding: 0; } 

#mainNav{ 
    width: 100%; 
    height: 35px; 
    background-color: #202020; 
    border-bottom: 1px solid #444; 
    overflow: hidden; 
} 

#mainNav ul{ 
    height: 35px; 
    list-style: none; 
} 

#mainNav ul li{ 
    float: left; 
    height: 35px; 
    padding-bottom: 0; 
    font-size: 17px; 
    border-right:1px solid #444; 
    background: -moz-linear-gradient(top, rgba(24,24,24,0) 60%, rgba(24,24,24,0.38) 90%, rgba(0,0,0,0.5) 100%); 
    background: -webkit-gradient(linear, left top, left bottom, color-stop(60%,rgba(24,24,24,0)), color-stop(90%,rgba(24,24,24,0.38)), color-stop(100%,rgba(0,0,0,0.5))); 
    background: -webkit-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: -o-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: -ms-linear-gradient(top, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    background: linear-gradient(to bottom, rgba(24,24,24,0) 60%,rgba(24,24,24,0.38) 90%,rgba(0,0,0,0.5) 100%); 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00181818', endColorstr='#80000000',GradientType=0); 
} 

#mainNav a { 
    height: 33px; 
    display: block; 
    line-height: 33px; 
    border-bottom: 2px solid #00a4ff; 
    color: #fff; 
    padding-left: 10px; padding-right: 10px; 
    text-decoration: none; 
    font-weight: bold; 
    font-family: sans-serif; 
}