所以,我想保持相同大小的框和相同的边框,但是我不想给整个背景上色。我只想给它中心的几个像素上色,在框的中间画一条红线。我可以通过创建另一个div元素来实现,但是我想用一个元素来完成这两件事。有可能吗?
background-color: red;
position: absolute;
margin: 120px 30px 0px 30px;
height: 140px;
width: 400px;
border: 0.2rem rgba(172, 255, 47, 0.565) solid;
这是它现在的样子,我想保持相同的框大小,而不是红色的孔框,我只想在中心有一条线,可以吗?
2条答案
按热度按时间qlvxas9a1#
我使用CSS伪元素插入红色的方框,然后使用css
transform
将方框定位在中间,这个解决方案是否符合您的要求?46scxncf2#
你想在一个绝对定位的框中间画一条红线,而不需要额外的html,你可以使用背景图片(线性渐变)。