CSS经验积累

 1.CLASS和ID的优先级比较.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>无标题 1</title>
<style type="text/css">
    .a h1
{
    color
:fuchsia;
}
    .b h1
{
    color
:lime;
}
    #a h1
{
    color
:fuchsia;
}
    #b h1
{
    color
:lime;
}

</style>
</head>

<body>
<div class="a">
    
<h1>CLASS在前</h1>
    
<div id="b">
        
<h1>ID在后</h1>
    
</div>
</div>
<div class="a">
    
<h1>CLASS在前</h1>
    
<div class="b">
        
<h1>CLASS在后</h1>
    
</div>
</div>
<div id="a">
    
<h1>ID在前</h1>
    
<div class="b">
        
<h1>CLASS在后</h1>
    
</div>
</div>
<div id="a">
    
<h1>ID在前</h1>
    
<div id="b">
        
<h1>ID在后</h1>
    
</div>
</div>

</body>

</html>

 结论:上面的代码说明了在CSS样式中ID的优先级别比CLASS要高.(IE 6 7 8 FF  C结果一致)

原文地址:https://www.cnblogs.com/answercard/p/1903639.html