選擇器
優先級
id>class>標籤名
標籤選擇器 標籤名爲判定條件
li{
background-color: #D0D0D0;
}
class類選擇器 class屬性作爲判定條件
class之間的優先級看定義先後
.pec{background-color: red;}
.grey{
background-color: darkgrey;
font-family: "宋體";
}
.yellow{
background-color: yellow;
font-family: "楷體";
}
id選擇器 id屬性爲判定條件
只能用一次 id屬性是爲了劃分頁面結構 不能重複
#first{color: red;}
屬性選擇器
[align]{ box-shadow: 0 0 5px black; }
並集選擇器 多個條件 或者關係
選擇器1,選擇器2 相當於if中的或者
* */
h2,h1,.red{
color: red;
}
交集選擇器 多個條件遞進 並且關係
選擇器1選擇器2
最多一個標籤選擇器,若出現必須寫在最前面
* */
div.green{
color: green;
}
後代選擇器 將html的結構體現在選擇器中
選擇器父 選擇器子
* */
div a{
color: red;
}
僞類選擇器:
a{color: grey;}
/a在懸停的時候才滿足條件/
a:hover{color: green;}
a:active{color: red;}