問題描述
我知道有一個(gè)官方的 CSS3 :checked
偽類,但是有沒有一個(gè) :unchecked
偽類,它們有相同的瀏覽器支持嗎?
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 的參考資料 沒有提到,但是這個(gè) whatwg 規(guī)范(不管是什么)的作用.
Sitepoint's reference doesn't mention one, however this whatwg spec (whatever that is) does.
我知道將 :checked
和 :not()
偽類結(jié)合起來(lái)可以達(dá)到相同的結(jié)果,但我還是很好奇:
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 */
}
w3c 推薦相同的技術(shù)
The w3c recommends the same technique
可以使用否定偽類來(lái)選中未選中的復(fù)選框:
An unchecked checkbox can be selected by using the negation pseudo-class:
:not(:checked)
推薦答案
:unchecked
沒有定義在 Selectors 或 CSS UI level 3 specs 中,也沒有出現(xiàn)在 Level 4 Selectors 中.
:unchecked
is not defined in the Selectors or CSS UI level 3 specs, nor has it appeared in level 4 of Selectors.
事實(shí)上,W3C 的引用取自 Selectors 4 規(guī)范.由于 Selectors 4 建議使用 :not(:checked)
,因此可以安全地假設(shè)沒有對(duì)應(yīng)的 :unchecked
偽.:not()
和 :checked
的瀏覽器支持是相同的,所以這應(yīng)該不是問題.
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.
這似乎與 :enabled
和 :disabled
狀態(tài)不一致,尤其是因?yàn)橐粋€(gè)元素既不啟用也不禁用(即語(yǔ)義完全不適用),但是對(duì)于這種不一致似乎沒有任何解釋.
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
不計(jì)算在內(nèi),因?yàn)橐粋€(gè)元素同樣不能是未檢查、檢查或不確定的,因?yàn)檎Z(yǔ)義不適用.)
(:indeterminate
does not count, because an element can similarly be neither unchecked, checked nor indeterminate because the semantics don't apply.)
這篇關(guān)于CSS3:未經(jīng)檢查的偽類的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!