CSS 有 :blur 选择器(伪类)吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11703241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does CSS have a :blur selector (pseudo-class)?
提问by BoltClock
I know there is a :focus
selector. I can't seem to find use of or documentation of a :blur
selector. Is there one?
我知道有一个:focus
选择器。我似乎找不到:blur
选择器的使用或文档。有吗?
回答by BoltClock
There is no :blur
pseudo-class in CSS.
:blur
CSS 中没有伪类。
The dynamic pseudo-classes, like other pseudo-classes and in fact all other selectors, represent states; they do not represent eventsor transitions between statesin terms of the document tree. To wit: the :focus
pseudo-class represents an element that is infocus; it does not represent an element that has just receivedfocus, nor does there exist a :blur
pseudo-class to represent an element that has just lostfocus.
该动态伪类,像其他伪类,事实上所有其他选择,代表国家; 它们不代表文档树方面的事件或状态之间的转换。即:在:focus
伪类表示的元素是在焦点; 它不代表刚刚获得焦点的元素,也不存在:blur
代表刚刚失去焦点的元素的伪类。
Similarly, this applies to the :hover
pseudo-class. While it represents an element which has a pointing device over it, there is neither a :mouseover
pseudo-class for an element that has just been pointed tonor a :mouseout
pseudo-class for an element that has just been pointed away from.
同样,这适用于:hover
伪类。虽然它表示一个元素,它上面有一个指针设备,但:mouseover
对于刚刚被指向的元素没有:mouseout
伪类,也没有对于刚刚被指向远离的元素的伪类。
If you need to apply styles to an element that is not infocus, you have two choices:
如果您需要将样式应用于未聚焦的元素,您有两种选择:
Use
:not(:focus)
(with less browser support):input:not(:focus), button:not(:focus) { /* Styles for only form inputs and buttons that do not have focus */ }
Declare a rule that applies to any element regardless of its focus state, and override for elements that have focus:
input, button { /* Styles for all form inputs and buttons */ } input:focus, button:focus { /* Styles for only form inputs and buttons that have focus */ }
使用
:not(:focus)
(浏览器支持较少):input:not(:focus), button:not(:focus) { /* Styles for only form inputs and buttons that do not have focus */ }
声明适用于任何元素的规则,无论其焦点状态如何,并覆盖具有焦点的元素:
input, button { /* Styles for all form inputs and buttons */ } input:focus, button:focus { /* Styles for only form inputs and buttons that have focus */ }
回答by Utkanos
No, CSS has no blur pseudo-selector, presumably because blur is more of an event than a state. (It would be unclear when something should lose its blur state).
不,CSS 没有模糊伪选择器,大概是因为模糊更像是一个事件而不是状态。(不清楚什么时候应该失去模糊状态)。
回答by Torsten Walter
All regular selectors are by default not focussed. So you don't need a special blur selector.
默认情况下,所有常规选择器都没有聚焦。所以你不需要一个特殊的模糊选择器。
These are the selectors by precedence.
这些是优先级的选择器。
.myButton
.myButton:hover
.myButton:focus
.myButton:active
回答by userDepth
Use the general transition to set the blur transition.
使用通用过渡设置模糊过渡。
.example {
transition-property: opacity;
transition-duration: 2s; /* This will happen after the hover state and can also be used for consistency on the overall experience */
opacity: 0;
}
.example:hover {
opacity: .8;
transition-duration: .3s;
transition-delay: .1s;
}