--- title: 虛擬類別 slug: Web/CSS/Pseudo-classes translation_of: Web/CSS/Pseudo-classes ---
{{ CSSRef() }}
CSS 虛擬類別(pseudo-class)的元素,在特殊狀態下被選取的話,會作為關鍵字被加到選擇器裡面。例如 {{ Cssxref(":hover") }} 會讓用戶的滑鼠停在某個元素的時候,套用指定選擇器的樣式。
虛擬類別與 {{ Cssxref("pseudo-elements") }} 能讓你不只能給文件樹(document tree)本身的相關內容套用樣式,還能給諸如瀏覽歷史({{ cssxref(":visited") }})、內容的狀態({{ cssxref(":checked") }})、還有滑鼠的位置(像 {{ cssxref(":hover") }} 就能讓偵測滑鼠是否在元件上)之類的外部相關因素套用樣式。
selector:pseudo-class {
property: value;
}
| 規範 | 狀態 | 註解 |
|---|---|---|
| {{ SpecName('Fullscreen') }} | {{ Spec2('Fullscreen') }} | 定義 :fullscreen。 |
| {{ SpecName('HTML WHATWG') }} | {{ Spec2('HTML WHATWG') }} | 在 {{ SpecName('HTML5 W3C') }} 並沒有改變。 |
| {{SpecName('CSS4 Selectors')}} | {{Spec2('CSS4 Selectors')}} | 定義 :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().沒有針對 {{SpecName('CSS3 Selectors')}} 與 {{SpecName('HTML5 W3C')}} 虛擬類別的重大更改(though semantic meaning not taken over) |
| {{ SpecName('HTML5 W3C') }} | {{ Spec2('HTML5 W3C') }} | 定義以下 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(). |
| {{ SpecName('CSS3 Basic UI') }} | {{ Spec2('CSS3 Basic UI') }} | 定義 :default, :valid, :invalid, :in-range, :out-of-range, :required, :optional, :read-only, :read-write,但沒有語意含義的定義。 |
| {{SpecName('CSS3 Selectors')}} | {{Spec2('CSS3 Selectors')}} | 定義 :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 的語法,但沒有語意含義的定義。在 {{SpecName('CSS2.1')}} 並沒有明顯改變。 |
| {{SpecName('CSS2.1')}} | {{Spec2('CSS2.1')}} | 定義 :lang(), :first-child, :hover, :focus.在 {{SpecName('CSS1')}} 並沒有明顯改變。 |
| {{SpecName('CSS1')}} | {{Spec2('CSS1')}} | 定義 :link, :visited, :active,但沒有語意含義的定義。 |