css 选择器分为以下四种:
1,html元素选择器
以html元素标签名字显示
body{ bgcolor:green; } p{ color: red; }
2,id 选择器
id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。
id 选择器以 "#" 来定义。在html主题中,id属性值始终是唯一的
<p id="red">这个段落是红色。</p> <p id="green">这个段落是绿色。</p> #red{ color:red; } #green { color:green; }
3 ,class类选择器
class选择器,以点(.)显示
<p class="center"> This paragraph will also be center-aligned. </p> .center { text-align: center; }
4,派生选择器,(html,id,class属性,都有派生选择器)
li strong { font-style: italic; font-weight: normal; } .center strong { font-style: italic; font-weight: normal; }
时间: 2024-07-30 10:02:24