CSS選擇器的語法規則(表格)

選擇器 例子 例子描述
.class .intro 選擇class="intro"的所有節點
#id #firstname 選擇id="firstname"的所有節點
* * 選擇所有節點
element p 選擇所有p節點
element,element div,p 選擇所有div節點和所有p節點
element element div p 選擇div節點內部的所有p節點
element>element div>p 選擇父節點爲div節點的所有p節點
element+element div+p 選擇緊接在div節點之後的所有p節點
[arttribute] [target] 選擇帶有target屬性的所有節點
[arttribute=value] [target=blank] 選擇target="blank"的所有節點
[arttribute~=value] [title~=flower] 選擇title屬性包含單詞flower的所有節點
:link a:link 選擇所有未被訪問的鏈接
:visited a:visited 選擇所有已被訪問的鏈接
:active a:active 選擇活動鏈接
:hover a:hover 選擇鼠標指針位於其上的鏈接
:focus input:focus 選擇獲得焦點的input節點
:first-letter p:first-letter 選擇每個p節點的首字母
:first-line p:first-line 選擇每個p節點的首行
:first-child p:first-child 選擇屬於父節點的第一個子節點的所有p節點
:before p:before 在每個p節點的內容之前插入內容
:after p:after 在每個p節點的內容之後插入內容
:lang(language) p:lang 選擇帶有以it開頭的lang屬性值的所有p節點
element~element2 p~ul 選擇前面有p節點的所有ul節點
[attribute^=value] a[src^=“https”] 選擇其src屬性值以https開頭的所有a節點
[attribute$=value] a[src$=".pdf"] 選擇其src屬性以.pdf結尾的所有a節點
[attribute*=value] a[src*=“abc”] 選擇其src屬性中包含abc子串的所有a節點
:first-of-type p:first-of-type 選擇屬於其父節點的首個p節點的所有p節點
:last-of-type p:last-of-type 選擇屬於其父節點的最後p節點的所有p節點
:only-of-type p:only-of-type 選擇屬於其父節點的唯一的p節點的所有p節點
:only-child p:only-child 選擇屬於其父節點的唯一子節點的所有p節點
:nth-child(n) p:nth-child 選擇屬於其父節點的第二個子節點的所有p節點
:nth-last-child(n) p:nth-last-child 同上,從最後一個子節點開始計數
:nth-of-type(n) p:nth-of-type 選擇屬於其父節點第二個p節點的所有p節點
:nth-last-of-type(n) p:nth-last-of-type 同上,但是從最後一個子節點開始計數
:last-child p:last-child 選擇屬於其父節點最後一個子節點的所有p節點
:root :root 選擇文檔的根節點
:empty p:empty 選擇沒有子節點的所有p節點(包括文本節點)
:target #news:target 選擇當前活動的#news節點
:enabled input:enables 選擇每個啓用的input節點
:disabled input:disabled 選擇每個禁用的input節點
:checked input:checked 選擇每個被選中的input節點
:not(selector) :not 選擇非p節點的所有節點
::selection ::seclection 選擇被用戶選取的節點部分
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章