实现边框的几种方式

页面布局代码

div{
    position: relative;
    width: 200px;
    line-height: 50px;
    background-color:#666666;
    color: #fff;
    margin-left: 20px;
    margin-top: 20px;
    box-sizing: border-box;
}
<body>
    <div class="bl">一个人去拉萨</div>
</body>
  1. 利用 border属性
    .bl{
        border-left: 3px solid #000000;
    }
  1. 利用伪元素实现
    .bl::after{
        position: absolute;
        top: 0;
        left: 0;
        content: '';
        display: block;
        width: 3px;
        height: 100%;
        background-color: #000000;
    }
  1. 利用box-shadow阴影属性
    .bl{
        box-shadow: -3px 0px 0 0 #000000;
    }
  1. 利用filter 滤镜实现
    .bl{
        filter: drop-shadow(-3px 0px 0px #000000);
    }
  1. 利用背景颜色渐变
    .bl{
        background-image:linear-gradient(90deg,#000000 0px, #000000 5px,transparent 5px)
    }

猜你喜欢

转载自www.cnblogs.com/D-Y-W/p/10577054.html