CSS基础选择器

派生选择器

index.html

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="mycss.css" type="text/css">
    </head>
    <body>
        <p><strong>我是黑色,因为我不在列表当中,所以这个规则对我不起作用</strong></p>
        <u1>
            <li><strong>我是红色,这是因为 strong 元素位于 li 元素内。</strong></li>
        </u1>
    </body>
</html>

mycss.css

li strong{
    color: red;
}

id选择器
id 选择器以“#”来定义

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link  href="MyCss.css" type="text/css" rel="stylesheet">
    </head>
    <body>
        <p id="pid">hello css<a href="www.shiyanlou.com">shiyanlou</a></p>
        <div id="divid">this is a div</div>

    </body>
</html>
#pid a{
    color:#00755f;
}
#divid {
    color: red;
    }

类选择器
在 CSS 中,类选择器以一个点号显示:

.divclass {
    color: red;
}
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link  href="MyCss.css" type="text/css" rel="stylesheet">
    </head>
    <body>
    <!--p 标签中嵌套了一个 a 标签,在下面的 css 引用过程中我们可以看到的.pclass a 即为 class 被用作派生选择器-->
        <p class="pclass">这是一个 class 显示效果<a href="http://www.shiyanlou.com">效果</a></p>
        <div class="divclass">hello div</div>
    </body>
</html>
.pclass a{
    color: green;
}
.divclass {
    color: red;
}

属性选择器

带有 title 属性、属性和值选择器 title=”te” 的所有元素设置样式

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            [title]{
                color: #00ff14;
            }
            [title=te]{
                color: red;
            }

        </style>    
    </head>
    <body>
       <p title=>属性选择器</p>
        <p title="te">属性和值选择器</p>
    </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值