CSS选择器
CSS选择器
id和class的选择器
在设置CSS样式的时候,需要在元素中设置"id"和"class"选择器。
id选择器
HTML元素用id属性来设置id选择器,CSS中id选择器用到"#"定义。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>举例子</title>
<style>
#para{
text-align:center;
color:red;
}
</style>
</head>
<body>
<p id="para">HelloWorld!!</p>
</body>
</html>
#para{
text-align:center;
color:red;
}
class选择器
HTML元素用class属性来设置class选择器,CSS中class选择器用"."定义。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>举个例子</title>
<style>
.center {
text-align: center;
}
</style>
</head>
<body>
<h1 class="center">居中</h1>
</body>
</html>
.center{
text-align:center;
}

浙公网安备 33010602011771号