实现HC中制作0.5px的边框

通常使用两种方法,适合做上下边框,侧边框则会变得十分麻烦,不建议使用

 

1.border + border-image + linear-gradient 方法

使用线性渐变遮住0.5px大小的边界

<div class="border"></div>
  .border{
        width:200px;
        height: 200px;
        background-color: red;
        margin: 0 auto ;
        border-bottom:  1px solid blue;
        border-image: linear-gradient( to bottom,transparent  50%,Green 50%) 0 0 100% 0 ;
    }

 

2.伪元素 + background-image 方法

利用伪元素盖住0.5px的边框

 <div class="border"></div>
 .border { 
    width: 200px;
    height: 200px;
    background-color: red;
    margin: 0 auto;
    position: relative;
  }
.border:before {
    content: " ";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100px;
    height: 1px;
    background-color: blue;
    background-image: linear-gradient(to bottom transparent 50%, blue 50%);
  }
posted @ 2022-10-12 22:10  Dollom  阅读(35)  评论(0)    收藏  举报