css 画一条线 从中间往两边延伸
时间: 2023-09-06 16:14:18 浏览: 82
好的,可以使用CSS的伪元素:before和:after,设置宽度为50%,然后用绝对定位让两个伪元素各自占据了部分线条的位置,再设置边框样式。以下是实现代码:
```css
.line {
position: relative;
width: 50%;
height: 1px;
background-color: black;
}
.line:before,
.line:after {
position: absolute;
content: "";
top: 0;
height: 100%;
border-top: 1px solid black;
width: 50%;
}
.line:before {
left: 0;
}
.line:after {
right: 0;
}
```