★選擇器
★元素選擇器
<a class="myClass" href="index.html">點(diǎn)擊跳轉(zhuǎn)</a>
<span class="myClass">另一文本</span>
<style type="text/css">
a {
background: gray;
color: #6a90d9;
}
</style>
效果:作用于 HTML 文檔中的所有 a 標(biāo)簽的元素上
★id選擇器
<a id="myId" href="index.html">點(diǎn)擊跳轉(zhuǎn)</a>
<style type="text/css">
#myId {
background: gray;
color: #6a90d9;
}
</style>
id選擇器唯一性 id 選擇器只作用于單個元素
<a class="myClass" href="index.html">點(diǎn)擊跳轉(zhuǎn)</a>
<span class="myClass">另一文本</span>
<style type="text/css">
.myClass {
background: gray;
color: #6a90d9;
}
</style>
文檔中可對多個元素應(yīng)用相同 class幻件,所以 class 可同時作用于多個元素
★屬性選擇器
<a class="myClass" href="index.html">點(diǎn)擊跳轉(zhuǎn)</a>
<span class="myClass">另一文本</span>
<style type="text/css">
[href] {
background: gray;
color: #6a90d9;
}
</style>
作用于所有具有 href 屬性的元素,不管有沒有使用
★組合選擇器
<a class="myClass" href="index.html">點(diǎn)擊跳轉(zhuǎn)</a>
<span class="myClass">另一文本</span>
<style type="text/css">
a.myClass {
background: gray;
color: #6a90d9;
}
</style>
元素選擇器和 class 選擇器組合使用,作用于 a 元素中有聲明 myClass 類型的元素
★通用選擇器
<style type="text/css">
* {
background: gray;
}
</style>
選擇到全局元素身上