【发布时间】:2016-05-17 19:08:26
【问题描述】:
我在这里阅读了很多关于此主题的问题(1、2、3 等),但我没有找到与我完全相同的示例。
所以我想将样式设置为元素,但在 :hover 中的父级时覆盖它。
类似这样的:
少
.gray-images > li > a {
img {
-webkit-filter: grayscale(1);
-moz-transition: all .2s ease;
-o-transition: all .2s ease;
-webkit-transition: all .2s ease;
transition: all .2s ease;
selector { /* <-- That's what I'm looking for I want to override it when the user hover on the `a` element */
-webkit-filter: grayscale(0);
}
}
}
html
<ul class="gray-images">
<li>
<a href="#href">
<img src="the_src" height="20"></a>
</li>
</ul>
简单来说:我想将a 中的img 设置为grayscale:1。当 img 的父级(a 标签)上的用户 :hover 将图像设置为 grayscale:0。
我知道有一个技巧,比如将父选择器定义为变量并使用它 2 次。但我的问题是是否有一种“直接”的方式来做到这一点。谢谢!
【问题讨论】: