CSS:第1课
CSS选择器有:id选择器、派生选择器
1、id选择器
id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。
id 选择器以 "#" 来定义。
#red {color:red;} #green {color:green;} <p id="red">这个段落是红色。</p> <p id="green">这个段落是绿色。</p>
2、派生选择器
在现代布局中,id 选择器常常用于建立派生选择器。
#sidebar p { font-style: italic; text-align: right; margin-top: 0.5em; }
3、类选择器
class选择器通常用点号(.)来显示
4、属性选择器
二、CSS中的样式优先级
内联样式 <style font-size="16px">
内部样式表 <style type="text/css">......</style>
外部样式表 <link rel="stylesheet" type="text/css" href="mystyle.css" />
精确匹配大于模糊匹配
1、id选择器
2、class类选择器
3、span标签选择器
4、*
注明:谁离标签近,谁的优先级就最高。同等水平时,比较精确。
三、CSS选择器主要有以下10类
1、通配选择器:*{margin:0px;}
2、类型选择器:a{text-decoration:none;}
3、属性选择器:input[type="button"]{padding:5px;}
4、包含选择器:div.code a{text-decoration:none;}
5、子对象选择器:ul.test>li{font-size:14px;}
6、ID选择器:#test {color:red;}
7、类选择器:.test{color:red;}
8、选择器分组:body,ul,li{margin:0px;}
9、伪类及伪对象选择器:div:first-letter{font-size:16px;}、a.test:hover{text-decoration:underline;}
10、相邻选择器:li+li{font-weight:bold;}
四、