CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明。
css外部表
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
选择器
selector {declaration1; declaration2; ... declarationN }
body {
color: #000;
background: #fff;
margin: 0;
padding: 0;
font-family: Georgia, Palatino, serif;
}
id 选择器
id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。
id 选择器以 “#” 来定义
#red {color:red;}
#green {color:green;}
<p id="red">这个段落是红色。</p>
<p id="green">这个段落是绿色。</p>
CSS 类选择器
.center {text-align: center}
<h1 class="center">
This heading will be center-aligned
</h1>
<p class="center">
This paragraph will also be center-aligned.
</p>