一直對(duì)這個(gè)地方糊里糊涂,這次借了一本書(shū),爭(zhēng)取將css強(qiáng)化一下.
CSS的幾種選擇器:
另外,可以通過(guò)這幾種選擇器組合定義復(fù)合選擇器,例如:
CSS的幾種選擇器:
- 標(biāo)記選擇器:
<style>
h1{
color:red
}
</style>
<h1>This is test.</h1>
h1{
color:red
}
</style>
<h1>This is test.</h1>
- 類(lèi)別選擇器:
<style>
.red{
color:red
}
</style>
<p class="red">xxxxxx</p>
.red{
color:red
}
</style>
<p class="red">xxxxxx</p>
- ID選擇器:
<style>
#firstPar{
color:red
}
</style>
<p id="firstPar">xxxxxx</p>
#firstPar{
color:red
}
</style>
<p id="firstPar">xxxxxx</p>
- 復(fù)合選擇器:
另外,可以通過(guò)這幾種選擇器組合定義復(fù)合選擇器,例如:
<style>
p{
color:red
}
p .firstPar{
color:blue
}
.firstPar{
color:green
}
</style>
<p>普通段落</p>
<p class="firstPar">第一段</p>
<h1 class="firstPar">第一段標(biāo)題</h1>
p{
color:red
}
p .firstPar{
color:blue
}
.firstPar{
color:green
}
</style>
<p>普通段落</p>
<p class="firstPar">第一段</p>
<h1 class="firstPar">第一段標(biāo)題</h1>
- 全局選擇器:
<style>
*{
color:red;
font-size:10px
}
</style>
<p>普通段落</p>
<p>第一段</p>
<h1>第一段標(biāo)題</h1>
*{
color:red;
font-size:10px
}
</style>
<p>普通段落</p>
<p>第一段</p>
<h1>第一段標(biāo)題</h1>
- 后代選擇器:
<style>
p span{
color:red;
font-size:10px
}
span{
color:green
}
</style>
<p>嵌套使<span>用CSS</span>標(biāo)記的方法</p>
嵌套之外的<span>標(biāo)記</span>不生效
p span{
color:red;
font-size:10px
}
span{
color:green
}
</style>
<p>嵌套使<span>用CSS</span>標(biāo)記的方法</p>
嵌套之外的<span>標(biāo)記</span>不生效