CSS經驗積累

來源:互聯網
上載者:User

 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結果一致)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.