Is there an opposite CSS pseudo-class to :hover?(是否有与 :hover 相对的 CSS 伪类?)
问题描述
CSS中是否有伪类来指定
Is there a pseudo-class in CSS to specify
:not(:hover)
或者这是指定未悬停的项目的唯一方法?
Or is that the only way to specify an item that is not being hovered?
我浏览了几个 CSS3 引用,但我没有看到任何提到 CSS 伪类来指定 :hover 的反面.
I went through several CSS3 references, and I see no mention of a CSS pseudo-class to specify the opposite of :hover.
推荐答案
是的,使用 :not(:hover)
.child:not(:hover){
opacity: 0.3;
}
.child {
display: inline-block;
background: #000;
border: 1px solid #fff;
width: 50px;
height: 50px;
transition: 0.4s;
}
.child:not(:hover) {
opacity: 0.3;
}
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
另一个例子;我想你想:当一个悬停时,使所有其他元素变暗".
Another example; I think you want to: "when one is hovered, dim all other elements".
如果我的假设是正确的,并且假设所有选择器都在同一个父级中:
If my assumption is correct, and assuming all your selectors are inside the same parent:
.parent:hover .child{
opacity: 0.2; // Dim all other elements
}
.child:hover{
opacity: 1; // Not the hovered one
}
.child {
display: inline-block;
background: #000;
border: 1px solid #fff;
width: 50px;
height: 50px;
transition: 0.4s;
}
.parent:hover .child {
opacity: 0.3;
}
.parent .child:hover {
opacity: 1;
}
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
否则……只需使用默认逻辑:
Otherwise... simply use the default logic:
.child{
opacity: 0.2;
}
.child:hover{
opacity: 1;
}
这篇关于是否有与 :hover 相对的 CSS 伪类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有与 :hover 相对的 CSS 伪类?
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
