CSS的基本选择器(三种)标签选择器class选择器id选择器


<html>
<head>
    <meta charset="UTF-8">
    <title>CSS的基本选择器</title>
    <style type="text/css">
        /* 标签选择器 */
        p {
            background-color: red;
            color: yellow;
        }

        div.div1 {
            background-color: blue;
        }
        div[class="div2"] {
            background-color: deeppink;
        }

        /* 类选择器 */
        .grayclass {
            background-color: gray;
        }

        /* id 选择器 */
        p#orangeid {
            background-color: orange;
        }

        #blackid {
            background-color: green;
        }

        /* 通配符选择器 */
        * {
            background-color: black;
            /* 清除所有 html 标记的默认外、内边距
            margin: 0;
            padding: 0;*/
        }

        /* h2 类型的标题居中 */
        h2 {
            text-align: center;
        }
    </style>
</head>
<body>
<h2 align="right">我是标题</h2>    <!-- 优先级被压制 -->
<p>&lt;p&gt;标签选择器</p>

<!-- class选择器: 每个html标签都有一个属性 class -->
<div class="div1">div.div1 选择器</div>
<div class="div2">div[class="div2"] 属性选择器</div>

<div class="grayclass">.grayclass 选择器</div>
<p class="grayclass">.grayclass 选择器</p>

<!-- id选择器: 每个html标签上面有一个属性 id -->
<p id="orangeid">p#orangeid 选择器</p>

<p id="blackid">#blackid 选择器</p>
<div id="blackid">#blackid 选择器</div>

</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值