img:after {
content:attr(title);
}
这不起作用,可能是因为 img 标签是空的,没有结束标签。有什么解决方法可以在没有 js 的情况下解决这个问题吗?
最佳答案
img
是一个替换元素,w3c CSS 2.1 spec说:
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.
我不知道发生了什么“ future 规范”。它在 Chrome 中不起作用,这是肯定的:)。
关于IMG 标签的 CSS 内容属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6009176/