在打印时显示图像alt文本
我想在打印网页时显示图像alt文本而不是图像。我尝试了此操作,但它不起作用,可能是因为IMG没有关闭标签,因此伪元素不适用于IMG。有办法这样做吗?
@media print {
img::after {
content: "attr(alt)";
}
}
I would like to display image alt text instead of image when printing the webpage. I tried this but it doesn't work, probably because img doesn't have a closing tag so the pseudo-elements doesn't work with img. Is there a way to do this?
@media print {
img::after {
content: "attr(alt)";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码无法正常工作,因为您将
:: after
分配给img
。img
不能生孩子。因此,您无法将其设置为::之后::在
之前。您可以做到这一点:
index.html:
style.css:
Your code is not working because you are assigning
::after
toimg
.img
can't have a child. So you can not set::after ::before
to it.you can do this:
index.html:
style.css: