如何实现0.5px边框

css 高频面试题:
如何实现0.5px 的边框
其实设置border为0.5px 是不可以的,有些浏览器会把他渲染成1px 。
下面介绍几种实现0.5px 边框的方法

一、单边框

1、border+border-image+linear-gradient的方式

  <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的方式

 <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%);
    }

3、定位+伪元素+transfrom缩放(scale)的方式

 <div class="border"></div>

 .border {
        width: 200px;
        height: 200px;
        background-color: red;
        margin: 0 auto;
        position: relative;
    }





©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容