通用屬性選擇符[ ]
例如:img[title]、input[type=”text”]
以此開頭屬性選擇符[^=xxx]
例如:a[href^=”http://”]
以此結尾屬性選擇符[$=xxx]
例如:a[href$=”.pdf”]
符合此所有屬性選擇符[*=xxx]
例如:img[src*=”logo”]
:first-child——第1個子元素
:last-child——最后1個子元素
:only-child——唯一子元素
:nth-child(odd)——奇數子元素
:nth-child(even)——偶數子元素
:nth-child(2)——第2個子元素
:nth-child(3n)——第3個子元素及3的倍數子元素
:nth-child(3n+1)——第3+1個子元素及3的倍數+1子元素
:nth-child(-n+3)——第3個子元素之前的所有元素
:first-of-type——符合特定標簽類型的第1個子元素
例如:.sidebar p:first-of-type 選取.sidebar類中第1個<p>標簽
:last-of-type——符合特定標簽類型的最后1個子元素
例如:.sidebar p:last-of-type 選取.sidebar類中最后1個<p>標簽
:nth-of-type(xxx)——類似:nth-child(xxx)
+:選取相鄰兩個同輩元素
例如:h2+p,選取h2及相鄰p元素
~:選取指定類型的所有同輩元素
例如:h2~p,選取h2同輩的所有p元素
:target選擇符:依賴于ID屬性,要使用ID連接到網頁中的特定位置
例如:<a href=”#ID”>超鏈接至form</a>
<form id=”ID”>XXX</form>
#ID:target——點擊<a>后form成為target
:not()選擇符:選取不符合條件的標簽
例如:p:not(.aaa)
!not()只能使用簡單選擇符,不能使用情況如下:
1、后代選擇符(div p a)。
2、偽元素選擇符(:hover)
3、群組或組合選擇符(h2 + p)
4、同時使用多個not()選擇符( p:not(#ID):not(.class) )
標簽選擇符:+1(包括偽元素)
類選擇符:+10(包括偽類)
ID選擇符:+100
行內樣式:+1000
例如:
a:hover 1+10=11
p:first-line 1+1=2
屬性后面添加!import忽略優先級,直接覆蓋屬性
例如:
.nav a {color:red}
a{color:teal !import},直接覆蓋color:red
新聞熱點
疑難解答