是否有与 :hover 相对的 CSS 伪类?
- 作者: 内涵大神你米哥
- 来源: 51数据库
- 2022-10-20
问题描述
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;
}
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
