虛擬類別
CSS 虛擬類別(pseudo-class)的元素,在特殊狀態下被選取的話,會作為關鍵字被加到選擇器裡面。例如 :hover
(en-US) 會讓用戶的滑鼠停在某個元素的時候,套用指定選擇器的樣式。
虛擬類別與 pseudo-elements
(en-US) 能讓你不只能給文件樹(document tree)本身的相關內容套用樣式,還能給諸如瀏覽歷史(:visited
(en-US))、內容的狀態(:checked
(en-US))、還有滑鼠的位置(像 :hover
(en-US) 就能讓偵測滑鼠是否在元件上)之類的外部相關因素套用樣式。
語法
selector:pseudo-class { property: value; }
基本虛擬類別的目錄
:active
(en-US):any
(en-US):checked
(en-US):default
(en-US):dir()
(en-US):disabled
(en-US):empty
(en-US):enabled
(en-US):first
(en-US):first-child
:first-of-type
:fullscreen
(en-US):focus
(en-US):hover
(en-US):indeterminate
(en-US):in-range
(en-US):invalid
(en-US):lang()
:last-child
(en-US):last-of-type
(en-US):left
(en-US):link
(en-US):not()
(en-US):nth-child()
(en-US):nth-last-child()
(en-US):nth-last-of-type()
(en-US):nth-of-type()
(en-US):only-child
(en-US):only-of-type
(en-US):optional
(en-US):out-of-range
(en-US):read-only
(en-US):read-write
(en-US):required
(en-US):right
(en-US):root
(en-US):scope
(en-US):target
:valid
(en-US):visited
(en-US)
規範
規範 | 狀態 | 註解 |
---|---|---|
Fullscreen API | Living Standard | 定義 :fullscreen 。 |
HTML Living Standard | Living Standard | 在 HTML5 並沒有改變。 |
Selectors Level 4 | Working Draft | 定義 :any-link , :local-link , :scope , :active-drop-target , :valid-drop-target , :invalid-drop-target , :current , :past , :future , :placeholder-shown , :user-error , :blank , :nth-match() , :nth-last-match() , :nth-column() , :nth-last-column() , and :matches() .沒有針對 Selectors Level 3 與 HTML5 虛擬類別的重大更改(though semantic meaning not taken over) |
HTML5 | Recommendation | 定義以下 HTML context 的語意含義: :link , :visited , :active , :enabled , :disabled , :checked , and :indeterminate .定義 :default , :valid , :invalid , :in-range , :out-of-range , :required , :optional , :read-only , :read-write , and :dir() . |
CSS Basic User Interface Module Level 3 | Recommendation | 定義 :default , :valid , :invalid , :in-range , :out-of-range , :required , :optional , :read-only , :read-write ,但沒有語意含義的定義。 |
Selectors Level 3 | Recommendation | 定義 :target , :root , :nth-child() , :nth-last-of-child() , :nth-of-type() , :nth-last-of-type() , :last-child , :first-of-type , :last-of-type , :only-child , :only-of-type , :empty , :not() .定義 :enabled , :disabled , :checked , :indeterminate 的語法,但沒有語意含義的定義。在 CSS Level 2 (Revision 1) 並沒有明顯改變。 |
CSS Level 2 (Revision 1) | Recommendation | 定義 :lang() , :first-child , :hover , :focus .在 CSS Level 1 並沒有明顯改變。 |
CSS Level 1 | Recommendation | 定義 :link , :visited , :active ,但沒有語意含義的定義。 |