css规则
选择器(即要改变样式的html元素)+声明(属性和属性值);(分号表示结束一条声明)
h1 { color: blue;}
- id选择器
为一类样式取一个id(以#表示),将要使用这种样式的元素的id都命名成样式的id
<head>
<style>
#para1{ color: blue;}
</style>
</head>
<body>
<h1 id="para1">muhan</h1>
</body>
- class选择器
- 类选择器以一个点"."号显示
<head> <style> .center { text-align:center;} </style> </head> <body> <h1 class="center">muhan</h1> <p class="center">muhan</p> </body>
- 指定特定的HTML元素使用class
<head> <style> p.center { text-align:center;} </style> </head> <body> <h1 class="center">muhan</h1> /*该文字不会居中,不会显示center类的样式*/ <p class="center">muhan</p> </body>
插入样式表
(在下文代码中注释,不单独说明)
- 外部样式表
- 内部样式表
- 内联样式