精通CSS——chapter2(为样式找到应用目标)

层叠和特殊性
<head>
    <meta charset="UTF-8">
    <title>Chapter 2</title>
    <style type="text/css">
        #content div#main-content h2{
            color:gray;
        }
        #content #main-content>h2{
            color:blue;
        }
        body #content div[id="main-content"] h2{
            color:green;
        }
        #main-content div.news-story h2{
            color:orange;
        }
        #main-content [class="news-story"] h2{
            color:yellow;
        }
        div#main-content div.news-story h2.first{
            color:red;
        }
    </style>
</head>
<body>
    <div id="content">
        <div id="main-content">
            <h2>Strange Times</h2>
            <p>Here you can read bizarre new stories from around</p>
            <div class="news-story">
                <h2 class="first">Bog Snorkeling Champion</h2>
                <p>The 2088 bog</p>
            </div>
        </div>
    </div>
</body>
这里的结果就是Strange Times和Bog Snorkeling都是灰色的,因为第一个选择器中有两个ID选择器组成,因此它具有最高特殊性
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值