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)";
}
}
Your code is not working because you are assigning
::aftertoimg.imgcan't have a child. So you can not set::after ::beforeto it.you can do this:
index.html:
style.css: