使用伪元素的 content 属性改变 img
Use pseudo element's content attribute to change img
我正在尝试使用动画和替换图像制作闪烁效果。这是我的代码,请告诉我哪里出错了。
HTML代码
<img class="lantern red" src="images/lantern.png">
CSS代码
.lantern::before {
content: url("images/lantern_twinkless.png"); position: absolute; display: block; width: 100%; height: 100%
}
因为你 can not apply pseudo 图片上的元素,解决方法是使用图形标签
Note. This specification does not fully define the interaction of
:before and :after with replaced elements (such as IMG in HTML). This
will be defined in more detail in a future specification.
figure{
width: 200px;
height: 200px;
background: red;
position: relative;
margin: 0 auto
}
figure:before{
content: '';
position: absolute;
top: 0;
left: 20px;
width: 100%;
height: 100%;
background: green
}
<figure>
</figure>
我正在尝试使用动画和替换图像制作闪烁效果。这是我的代码,请告诉我哪里出错了。
HTML代码
<img class="lantern red" src="images/lantern.png">
CSS代码
.lantern::before {
content: url("images/lantern_twinkless.png"); position: absolute; display: block; width: 100%; height: 100%
}
因为你 can not apply pseudo 图片上的元素,解决方法是使用图形标签
Note. This specification does not fully define the interaction of :before and :after with replaced elements (such as IMG in HTML). This will be defined in more detail in a future specification.
figure{
width: 200px;
height: 200px;
background: red;
position: relative;
margin: 0 auto
}
figure:before{
content: '';
position: absolute;
top: 0;
left: 20px;
width: 100%;
height: 100%;
background: green
}
<figure>
</figure>