在html代码中,以 class="xxx" 指明div的css类;用 id="xxx" 定义一个div的id;
在css样式定义中,以 .abc 定义一个css类abc,一个类可以用到html多个元素;以 #abc 定义id为abc的元素的样式;
效果如下;
码; 第一个div的css类为"exp",第二个div的id为"exp",第三个和第四个div应用了css类"abc";
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>div id and class </title>
<style>
.exp{ width:200px; color:#F00; height:100px; border:3px solid #F00}
#exp{ width:300px; height:80px; color:#00F; border:3px solid #00F}
.abc{ width:150px; color:#0F0; height:60px; border:3px solid #0F0; background-color:#000}
</style>
</head>
<body>
<div class="exp">
div1, exp 类
</div>
<p></p>
<div id="exp">
div2, id 为exp
</div>
<p></p>
<div class="abc">div3 abc类</div>
<p></p>
<div class="abc">div3 abc类</div>
</body>
</html>