CSS3:未选中的伪类 [英] CSS3 :unchecked pseudo-class

查看:104
本文介绍了CSS3:未选中的伪类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个官方的CSS3 :checked 伪类,但有一个:unchecked 类,并且它们是否具有相同的浏览器支持?



Sitepoint的参考没有提及,但 whatwg规范( 。



我知道当:checked 和<$ c时,可以实现相同的结果$ c>:not()伪类被组合,但我仍然好奇:

  input [type =checkbox]:not(:checked){
/ * styles * /
}

编辑



w3c推荐的方法相同


可以使用否定伪类来选择未选中的复选框:

 : not(:checked)



解决方案

:未选中未在选择器或CSS UI级别3规范中定义,也未出现在选择器的第4级中。



事实上,来自W3C的引用是取自Selectors 4规范。由于选择器4 建议使用:not(:checked),可以假设没有相应的:unchecked pseudo。浏览器对:not():checked 的支持是完全相同的, p>

这可能与:enabled :disabled 状态,特别是因为一个元素既不能被启用也不被禁用(即语义完全不适用),但是对于这种不一致性没有任何解释。



:indeterminate 不计数,因为一个元素同样既不会被取消选中,也不会被选中,也不会不确定,因为语义不适用。 p>

I know there is an official CSS3 :checked pseudo-class, but is there an :unchecked pseudo-class, and do they have the same browser support?

Sitepoint's reference doesn't mention one, however this whatwg spec (whatever that is) does.

I know the same result can be achieved when the :checked and :not() pseudo-classes are combined, but i'm still curious:

input[type="checkbox"]:not(:checked) {
    /* styles */
}

Edit:

The w3c recommends the same technique

An unchecked checkbox can be selected by using the negation pseudo-class:

:not(:checked)

解决方案

:unchecked is not defined in the Selectors or CSS UI level 3 specs, nor has it appeared in level 4 of Selectors.

In fact, the quote from W3C is taken from the Selectors 4 spec. Since Selectors 4 recommends using :not(:checked), it's safe to assume that there is no corresponding :unchecked pseudo. Browser support for :not() and :checked is identical, so that shouldn't be a problem.

This may seem inconsistent with the :enabled and :disabled states, especially since an element can be neither enabled nor disabled (i.e. the semantics completely do not apply), however there does not appear to be any explanation for this inconsistency.

(:indeterminate does not count, because an element can similarly be neither unchecked, checked nor indeterminate because the semantics don't apply.)

这篇关于CSS3:未选中的伪类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆