码迷,mamicode.com
首页 > Web开发 > 详细

web标准中定义id与class有什么区别吗

时间:2014-06-01 12:35:10      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

 
bubuko.com,布布扣
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
    <head profile="http://www.w3.org/2000/08/w3c-synd/#">
    <meta http-equiv="content-language" content="zh-cn" />
    <meta http-equiv="content-type" content="text/html;charset=gb2312" />
    <title>blueidea</title>
    <style type="text/css">
    /*<![CDATA[*/
    #aa {
    color:red
    }
    .aa {
    color:blue
    }
    /*]]>*/
    </style>
    </head>
    <body>
    <div id="aa" class="aa">
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    </div>
    </body>
    </html>
bubuko.com,布布扣

 

bubuko.com,布布扣
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
<head profile="http://www.w3.org/2000/08/w3c-synd/#">
<meta http-equiv="content-language" content="zh-cn" />
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<title>blueidea</title>
<style type="text/css">
/*<![CDATA[*/
.a {
color:orange
}
.b {
background:#eee
}
.c {
border:1px solid red
}
/*]]>*/
</style>
</head>
<body>
<div class="a b c">aaaaaaaa</div>
</body>
</html>
bubuko.com,布布扣

 

一.

web标准中是不容许重复ID的,比如 div id="aa" 一个页面中不容许重复2次,而class 定义的是类,理论上可以无限重复的,这样需要多次引用的定义便可以使用他.

class还可以同时引用多个类,不同的类之间用空格隔开.


二.

属性的优先级问题,ID 的优先级要高于class,看上面的例子


三.

方便JS等客户端脚本,如果在页面中要对某个对象进行脚本操作,那么可以给他定义一个ID,否则只能利用遍历页面元素加上指定特定属性来找到它,这是相对浪费时间资源,远远不如一个ID来得简单.

web标准中定义id与class有什么区别吗,布布扣,bubuko.com

web标准中定义id与class有什么区别吗

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/aobingyan/p/3762859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!