参见英文答案 >
Does :before not work on img elements?6个
我试过这个,它运行正常
我试过这个,它运行正常
<p alt="world">hello</p>
用CSS
p::after { content: attr(alt); }
但是当我尝试时它不起作用
<img src="http://placehold.it/300x300" alt="my image caption">
用CSS
img::after { content: attr(alt); }
是否可以使用CSS输出img的替代文字?
请指出浏览器与您提供的任何解决方案兼容.
解决方法
这是设计的.
img标签是自动关闭(< tag />)标签,因此它们不包含“内容”.由于它们不包含任何内容,因此不能附加任何内容(即:: after)或prepended(即:: before).
其他自动关闭的HTML元素也是如此:
<area>
,<base>
,<br>
,<col>
,<command>
,<embed>
,<hr>
,<keygen>
,
<link>
,<meta>
,<param>
,<source>
,<track>
and<wbr>
这是(CSS2)规范所说的:
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. [2014: hasn’t happened yet]
资料来源:http://www.w3.org/TR/CSS2/generate.html#before-after-content
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。