基础语法:
selector {property: value}
h1,h2,h3,h4,h5,h6
{
color: green;
}
1.派生选择器:li strong {
font-style: italic;
font-weight: normal;
}
2.id选择器
#red {color:red}
<p id="red">hello</p>
id选择器和派生选择器
#sidebar p {
font-style: italic;
text-align: right;
margin-top: 0.5em;
}
3.类选择器
.center {text-align: center}
.fancy td {
color: #f60;
background: #666;
}
4.属性选择器[title]
{
color:red;
}
外部样式表:
<link rel="stylesheet" type="text/css" href="mystyle.css" />
内部样式表:
<style type="text/css">
hr {color: sienna;}
p {margin-left: 20px;}
body {background-image: url("images/back40.gif");}
</style>
多重样式:
h3 {
color: red;
text-align: left;
font-size: 8pt;
}
而内部样式表拥有针对 h3 选择器的两个属性:
h3 {
text-align: right;
font-size: 20pt;
}
假如拥有内部样式表的这个页面同时与外部样式表链接,那么 h3 得到的样式是:
color: red;
text-align: right;
font-size: 20pt;
即颜色属性将被继承于外部样式表,而文字排列(text-alignment)和字体尺寸(font-size)会被内部样式表中的规则取代。