<分区>
<分区>
试图在其下方制作有关图像的信息。但是有一个问题...伪元素不可见..
<img info="hey guys" src="http://i024.radikal.ru/1211/4c/809c7c2dfa74.jpg">
<div info="I'm working, but I'm inside the block"></div>
div {
height: 100px;
margin: 10px;
background: yellow;
}
div[info]::after, img[info]::after {
content: attr(info);
display: block;
margin: 3px;
color: black;
font-style: italic;
}
谢谢。
最佳答案
img
元素不能有伪元素,因为它们不能有子元素——::before
被插入到元素中。它看起来像这样:
<img><before></img>
或者至少 itt 没有被 spec 定义
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.
关于html - 伪元素与 img 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13553064/