简体   繁体   English

div的CSS边框样式

[英]css border styling for div

I have a div with right and bottom borders, but while applying the border color to right it looks incomplete(kind of breakage) because of the given html style. 我有一个带有右边界和底边界的div,但是由于给定的html样式,在向右应用边界颜色时,它看起来不完整(有点破损)。 Is there any css trick or any work around to override the right border will flow across in a nice way? 是否有任何CSS技巧或任何替代方法都可以很好地覆盖右边界?

.tb{
border-right:1px solid #ccc;
border-bottom:1px solid #ccc;
width:70px;
height:18px;
zoom:250%;
}
.bd{
border-right-color:red;   
}

<div>
<div style="float: left;"> 
    <div class="tb"> </div>
    <div class="tb bd"> </div>
    <div class="tb bd"> </div>
    <div class="tb bd"> </div>
    <div class="tb bd"> </div>
    <div class="tb"> </div>
    <div class="tb"> </div>
</div>
<div style="float: left;"> 
    <div class="tb"> </div>
    <div class="tb bd"> </div>
    <div class="tb bd"> </div>
    <div class="tb bd"> </div>
    <div class="tb bd"> </div>
    <div class="tb"> </div>     
    <div class="tb"> </div>
</div>
</div>

check the below link, 检查以下链接,

http://jsfiddle.net/gq7dc4rd/2/ http://jsfiddle.net/gq7dc4rd/2/

Try to add margin-bottom: -1px to .bd However it's not the best practise, but should help. 尝试将margin-bottom:-1px添加到.bd。但这不是最好的做法,但应该有所帮助。

.bd {
  margin-bottom:-1px;
}

http://jsfiddle.net/uoo5utbv/ http://jsfiddle.net/uoo5utbv/

It's just the way borders are rendered by most Browsers. 这只是大多数浏览器呈现边框的方式。 You can work around this by using fake borders as I did using ::after in my example: http://jsfiddle.net/maryisdead/mtwcee03/ 您可以像在示例中使用::after一样使用假边框来解决此问题: http : //jsfiddle.net/maryisdead/mtwcee03/

 .tb{ border-bottom:1px solid #ccc; width:70px; height:18px; zoom:250%; position: relative; padding-right:1px; } .tb::after{ background:#ccc; content:''; position:absolute; height:100%; right:0; top:0; width:1px; } .bd::after{ background:red; } 
 <p style="font:12px lucida grande"> <b>Note:</b> I have a div with right and bottom borders, but while applying the border color to right it looks incomplete(kind of breakage) because of the given html style, Is there any css trick or any work around to override the right border will stretch across in a nice way? </p> <div> <div style="float: left;"> <div class="tb"> </div> <div class="tb bd"> </div> <div class="tb bd"> </div> <div class="tb bd"> </div> <div class="tb bd"> </div> <div class="tb"> </div> <div class="tb"> </div> </div> <div style="float: left;"> <div class="tb"> </div> <div class="tb bd"> </div> <div class="tb bd"> </div> <div class="tb bd"> </div> <div class="tb bd"> </div> <div class="tb"> </div> <div class="tb"> </div> </div> </div> 

If you want to have the right border to "flow in a nice way", you can apply a class to the containing divs like so: 如果您希望有正确的边界以“以一种不错的方式流动”,则可以将一个类应用于包含的divs如下所示:

HTML HTML

<p style="font:12px lucida grande">
    <b>Note:</b> I have a div with right and bottom borders, but while applying the border color to right it looks incomplete(kind of breakage) because of the given html style, Is there any css trick or any work around to override the right border will stretch across in a nice way?
</p>
<div>
    <div class="border" style="float: left;"> 
        <div class="tb"> </div>
        <div class="tb bd"> </div>
        <div class="tb bd"> </div>
        <div class="tb bd"> </div>
        <div class="tb bd"> </div>
        <div class="tb"> </div>
        <div class="tb"> </div>
    </div>
    <div class="border" style="float: left;"> 
        <div class="tb"> </div>
        <div class="tb bd"> </div>
        <div class="tb bd"> </div>
        <div class="tb bd"> </div>
        <div class="tb bd"> </div>
        <div class="tb"> </div>     
        <div class="tb"> </div>
    </div>
</div>

CSS CSS

.tb{

    border-bottom:1px solid #ccc;
    width:70px;
    height:18px;
    zoom:250%;
}

.border{
    border-right:1px solid red;
    }   

Check the new DEMO . 检查新的DEMO

A way to do that by adding margin-bottom 一种通过在底部添加边距来做到这一点的方法

     .bd 
   {
      margin-bottom:-1px;
   }

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

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