aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/css/pseudo-classes/index.html
blob: 1a222e59cd4d786cf671a6cefdbfc9d47a057e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
title: 虛擬類別
slug: Web/CSS/Pseudo-classes
translation_of: Web/CSS/Pseudo-classes
---
<p>{{ CSSRef() }}</p>

<p>CSS <strong><em><dfn>虛擬類別(pseudo-class)</dfn></em></strong>的元素,在特殊狀態下被選取的話,會作為關鍵字被加到選擇器裡面。例如 {{ Cssxref(":hover") }} 會讓用戶的滑鼠停在某個元素的時候,套用指定選擇器的樣式。</p>

<p>虛擬類別與 {{ Cssxref("pseudo-elements") }} 能讓你不只能給文件樹(document tree)本身的相關內容套用樣式,還能給諸如瀏覽歷史({{ cssxref(":visited") }})、內容的狀態({{ cssxref(":checked") }})、還有滑鼠的位置(像 {{ cssxref(":hover") }} 就能讓偵測滑鼠是否在元件上)之類的外部相關因素套用樣式。</p>

<h2 id="語法">語法</h2>

<pre class="syntaxbox">selector:pseudo-class {
  property: value;
}
</pre>

<h2 id="基本虛擬類別的目錄">基本虛擬類別的目錄</h2>

<div class="index">
<ul>
 <li>{{ Cssxref(":active") }}</li>
 <li>{{ cssxref(':any')}}</li>
 <li>{{ Cssxref(":checked") }}</li>
 <li>{{ Cssxref(":default") }}</li>
 <li>{{ Cssxref(":dir", ":dir()")}}</li>
 <li>{{ Cssxref(":disabled") }}</li>
 <li>{{ Cssxref(":empty") }}</li>
 <li>{{ Cssxref(":enabled") }}</li>
 <li>{{ Cssxref(":first") }}</li>
 <li>{{ Cssxref(":first-child") }}</li>
 <li>{{ Cssxref(":first-of-type") }}</li>
 <li>{{ Cssxref(":fullscreen") }}</li>
 <li>{{ Cssxref(":focus") }}</li>
 <li>{{ Cssxref(":hover") }}</li>
 <li>{{ Cssxref(":indeterminate") }}</li>
 <li>{{ Cssxref(":in-range") }}</li>
 <li>{{ Cssxref(":invalid") }}</li>
 <li>{{ Cssxref(":lang", ":lang()") }}</li>
 <li>{{ Cssxref(":last-child") }}</li>
 <li>{{ Cssxref(":last-of-type") }}</li>
 <li>{{ Cssxref(":left") }}</li>
 <li>{{ Cssxref(":link") }}</li>
 <li>{{ Cssxref(":not", ":not()") }}</li>
 <li>{{ Cssxref(":nth-child", ":nth-child()") }}</li>
 <li>{{ Cssxref(":nth-last-child", ":nth-last-child()") }}</li>
 <li>{{ Cssxref(":nth-last-of-type", ":nth-last-of-type()") }}</li>
 <li>{{ Cssxref(":nth-of-type", ":nth-of-type()") }}</li>
 <li>{{ Cssxref(":only-child") }}</li>
 <li>{{ Cssxref(":only-of-type") }}</li>
 <li>{{ Cssxref(":optional") }}</li>
 <li>{{ Cssxref(":out-of-range") }}</li>
 <li>{{ Cssxref(":read-only") }}</li>
 <li>{{ Cssxref(":read-write") }}</li>
 <li>{{ Cssxref(":required") }}</li>
 <li>{{ Cssxref(":right") }}</li>
 <li>{{ Cssxref(":root") }}</li>
 <li>{{ Cssxref(":scope") }}</li>
 <li>{{ Cssxref(":target") }}</li>
 <li>{{ Cssxref(":valid") }}</li>
 <li>{{ Cssxref(":visited") }}</li>
</ul>
</div>

<h2 id="規範"><span>規範</span></h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">規範</th>
   <th scope="col">狀態</th>
   <th scope="col">註解</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('Fullscreen') }}</td>
   <td>{{ Spec2('Fullscreen') }}</td>
   <td>定義 <code>:fullscreen</code></td>
  </tr>
  <tr>
   <td>{{ SpecName('HTML WHATWG') }}</td>
   <td>{{ Spec2('HTML WHATWG') }}</td>
   <td>{{ SpecName('HTML5 W3C') }} 並沒有改變。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS4 Selectors')}}</td>
   <td>{{Spec2('CSS4 Selectors')}}</td>
   <td>定義 <code>:any-link</code>, <code>:local-link</code>, <code>:scope</code>, <code>:active-drop-target</code>, <code>:valid-drop-target</code>, <code>:invalid-drop-target</code>, <code>:current</code>, <code>:past</code>, <code>:future</code>, <code>:placeholder-shown</code>, <code>:user-error</code>, <code>:blank</code>, <code>:nth-match()</code>, <code>:nth-last-match()</code>, <code>:nth-column()</code>, <code>:nth-last-column()</code>, and <code>:matches()</code>.<br>
    沒有針對 {{SpecName('CSS3 Selectors')}}{{SpecName('HTML5 W3C')}} 虛擬類別的重大更改(though semantic meaning not taken over)</td>
  </tr>
  <tr>
   <td>{{ SpecName('HTML5 W3C') }}</td>
   <td>{{ Spec2('HTML5 W3C') }}</td>
   <td>定義以下 HTML context 的語意含義: <code>:link</code>, <code>:visited</code>, <code>:active</code>, <code>:enabled</code>, <code>:disabled</code>, <code>:checked</code>, and <code>:indeterminate</code>.<br>
    <code>定義 :default</code>, <code>:valid</code>, <code>:invalid</code>, <code>:in-range</code>, <code>:out-of-range</code>, <code>:required</code>, <code>:optional</code>, <code>:read-only</code>, <code>:read-write</code>, and <code>:dir()</code>.</td>
  </tr>
  <tr>
   <td>{{ SpecName('CSS3 Basic UI') }}</td>
   <td>{{ Spec2('CSS3 Basic UI') }}</td>
   <td>定義 <code>:default</code>, <code>:valid</code>, <code>:invalid</code>, <code>:in-range</code>, <code>:out-of-range</code>, <code>:required</code>, <code>:optional</code>, <code>:read-only</code>, <code>:read-write</code>,但沒有語意含義的定義。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Selectors')}}</td>
   <td>{{Spec2('CSS3 Selectors')}}</td>
   <td>定義 <code>:target</code>, <code>:root</code>, <code>:nth-child()</code>, <code>:nth-last-of-child()</code>, <code>:nth-of-type()</code>, <code>:nth-last-of-type()</code>, <code>:last-child</code>, <code>:first-of-type</code>, <code>:last-of-type</code>, <code>:only-child</code>, <code>:only-of-type</code>, <code>:empty</code>, <code>:not()</code>.<br>
    定義 <code>:enabled</code>, <code>:disabled</code>, <code>:checked</code>, <code>:indeterminate</code> 的語法,但沒有語意含義的定義。<br>{{SpecName('CSS2.1')}} 並沒有明顯改變。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>定義 <code>:lang()</code>, <code>:first-child</code>, <code>:hover</code>, <code>:focus</code>.<br>{{SpecName('CSS1')}} 並沒有明顯改變。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>定義 <code>:link</code>, <code>:visited</code>, <code>:active</code>,但沒有語意含義的定義。</td>
  </tr>
 </tbody>
</table>

<h2 id="參閱">參閱</h2>

<ul>
 <li>{{ Cssxref("pseudo-elements") }}</li>
</ul>