0
是否有可能在img元素上的伪选择器之前和之后使用?认为它是但没有任何运气,将CSS切换到一个div,它工作正常。 .page-overhang
类是img元素。:之前和之后:在img元素上的元素
// page overhang mixin
@mixin overhang {
&:before,
&:after {
position: absolute;
left: 0;
display: block;
width: 10px;
height: 18px;
background: url(../images/sprite.png) no-repeat;
content: "";
}
&:before {
top: -18px;
background-position: 0 -100px;
}
&:after {
bottom: -18px;
background-position: 0 -119px;
}
}
/* scss file */
.page-overhang {
position: relative;
display: block;
@include overhang();
}
':之前'和':之后'伪元素放置在元素的内部。如果该元素不能有子元素,':before'和':after'将不起作用。 – Shmiddty
谢谢,这很有道理,我猜从未尝试过在图像上使用它们。 – ferne97