下面是我对伪元素忽略填充的解决方案,但是它感觉有点“无趣”,因为我对伪元素使用了负值。
这个解决方案可以吗?
我也尝试使用left: 0; top: 0;,但是之后我将伪元素相对于页面的主体而不是元素进行定位。为什么?
CSS:
.block-header {
background-color: #3A658B;
height: 30px;
width: 100%;
line-height: 30px;
color: white;
font-size: 18px;
border-radius: 3px;
padding-left: 10px;
}
.block-header::before {
content: '';
position: absolute;
margin-left: -10px;
height: 30px;
width: 10px;
background-color: #1E3552;
border-radius: 3px 0px 0px 3px;
}发布于 2017-06-23 00:22:08
使用left: 0是可以的。这是正确的方法。
但是您还没有在position: relative元素上指定.block-header。
考虑到这一点:
.block-header {
background-color: #3A658B;
height: 30px;
line-height: 30px;
color: white;
font-size: 18px;
border-radius: 3px;
padding-left: 10px;
position: relative; /* NEW */
}
.block-header::before {
left: 0; /* NEW */
content: '';
position: absolute;
height: 30px;
width: 10px;
background-color: #1E3552;
border-radius: 3px 0px 0px 3px;
}<div class="block-header">test</div>
有关详细信息,请参阅MDN。
https://stackoverflow.com/questions/44711089
复制相似问题