CSS实现半边边框(只有边框的部分可见)
<div class="part box">
<h1>内容</h1>
<!-- 绘出下面两个对角边框-->
<div class="part-footer"></div>
</div>
- 主要代码
.box {
width: 100px;
height: 100px;
}
.part {
position: relative;
&::before {
position: absolute;
top: 0;
left: 0;
content: '';
width: 20px;
height: 20px;
border-left: 4px solid #4381ad;
border-top: 4px solid #4381ad;
}
&::after {
position: absolute;
top: 0;
right: 0;
content: '';
width: 20px;
height: 20px;
border-right: 4px solid #4381ad;
border-top: 4px solid #4381ad;
}
.part-footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
&::before {
position: absolute;
bottom: 0;
left: 0;
content: '';
width: 20px;
height: 20px;
border-left: 4px solid #4381ad;
border-bottom: 4px solid #4381ad;
}
&::after {
position: absolute;
right: 0;
bottom: 0;
content: '';
width: 20px;
height: 20px;
border-right: 4px solid #4381ad;
border-bottom: 4px solid #4381ad;
}
}
}

本文详细介绍了如何利用CSS的position属性和伪元素(::before和::after)来实现在div元素中显示只有一半边界的边框效果,包括对角和底部边界。
539

被折叠的 条评论
为什么被折叠?



