是否可以在 img 元素上使用前后伪选择器?认为它是但没有任何运气,将 css 切换到 div 并且它工作正常。 .page-overhang
类是 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
伪元素不能用于 void elements ,因为它们指定要添加到元素实际内容之前或之后的内容,而 void 元素可以没有内容。
关于html - :before and :after elements on an img element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13870635/