一:规范
实现结构(html)、样式(css)、行为的分离(js)
二:css在html中的声明
如果直接写css
<style type="text/css">
p{font-size:9pt;}
</style>
如果链接css文件
<link rel="stylesheet" id="css_widthauto" type="text/css" href="mystyle.css
" />
三:选择器
1:类选择器
选择元素.类名
html文件
<h1 class="center">
This heading will be center-aligned
</h1>
<p class="center">
This paragraph will also be center-aligned.
</p>
css文件
h1.center {
color: #f60;
background: #666;
}
2:id选择器
选择元素#id值
html文件
<p id="red">这个段落是红色。</p>
<p id="green">这个段落是绿色。</p>
css文件
#red {color:red;}
#green {color:green;}
3:派生选择器
html文件
<h1 class="center">
<strong class="a"> This heading will be center-aligned</strong>
</h1>
<p class="left">
<strong class="a">This paragraph will also be center-aligned.</strong>
</p>
css文件
h1.center strong.a {
color: #f60;
background: #666;
}
4:属性选择器
input[type="text"]
{
width:150px;
display:block;
margin-bottom:10px;
background-color:yellow;
font-family: Verdana, Arial;
}
注:font-family是对字体的列举,各种浏览器会按各自的优先级来选取字体