【发布时间】:2015-06-27 10:12:55
【问题描述】:
是否可以将img 元素更改为其父a 标签的href 属性?例如,如果我有:
<a class="img-parent" href="http://placehold.it/400x200">
<img class="img-class" src="http://placehold.it/90x90" alt="This will change" />
</a>
我可以仅使用 CSS 更改img 的内容吗?
我知道我可以使用以下代码更改img,但我可以将其指向父级的href 属性吗?
.img-class{
content:url("http://placehold.it/400x200");
}
【问题讨论】:
-
不,不可能,据我所知。
-
我认为 content:url 仅用于 :before 和 :after 伪元素是 CSS
-
@AndrewAshton 令人惊讶的是它的工作原理
-
@ISuthanBala 这取决于您使用的浏览器;似乎适用于 Chrome,但不适用于 Firefox。
-
无论如何我认为用 CSS 不可能做到这一点,你需要使用 JavaScript。
标签: html image css css-selectors