选择器的一些类型和优先级别问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选择器</title>
</head>
<style>
    div{
        color: blue;
         /* text-align: center;使其在页面居中 */
        /* line-height: 0; 在页面的高度 */
    }
/* 标签选择器选择方法 */
    .father{
        color: red;
    }
/* class选择器选择方法 */
    .father .son .grandson{
        color: green;
         /* text-align: center;使其在页面居中 */
        /* line-height: 0; 在页面的高度 */
    }
/* 后代选择器的选择方法 */
     h1{
        color: pink;
        /* text-align: center;使其在页面居中 */
        /* line-height: 0; 在页面的高度 */
    }
/* css文本样式的可在div标签里面应用 */
    

    .first{
       color: green;
       text-align: center;
       line-height: 0;
    }
    table{
        color: red;
        text-align: center;
        line-height: 0;
    }
    tr{
        color: red;
        text-align:center;
        line-height: 0;
    } 
/* 部分文本样式是不能在table标签中使用的,如text-align */

/* 同级选择器的选择方法 */
    .one+li{
        text-align: center;
        color: yellowgreen;
    }
/* 1.同级相邻选择法:对所选中的选择器的相邻的下一个同级选择器进行选择 */
    .one~li{
        text-align: center;
        color: skyblue;
    }
/* 2.同级所有选择法:对除所选中的选择器外的所有同级选择器进行选中 */
/* 文本样式可以应用于表单标签中 */
    a{
        text-align: center;
        line-height: 100px;
        text-decoration-color:red;
    }
/* 部分文本样式可以应用于a标签中 */

/* 选择器的优先级 */
/* 1.同类选择器以顺序为后填写,排在下面的优先 */
    div{
        color: red;
    }
    div{
        color: pink;
    }
/* 2.不同选择器的优先级别不同,id选择器>类选择器>标签选择器 */
    div{
        text-align: right;
    }
    .a{
        text-align: center;
    }
    #b{
        text-align: left;
    }
/* 3.选择器的个数越多,优先级越高 */
    /* 0,0,1 */
    p{
        color: blueviolet;
    }
    /* 0,0,2 */
    body p{
        color: aqua;
    }
/* 优先级计算方法:
   (百)(个)(十)
     id  class 标签 */
     /* 0,1,0 */
    .you{
        color: red;
    }
    /* 0,1,1 */
    .you,p{
        color: green;
    }
    /* 1,0,0 */
    #me{
        color: brown;
    }
    /* 1,0,1 */
    #me,p{
        color: skyblue;
    }
    /* 1,1,0 */
    #me,.you{
        color: yellow;
    }
    /* 1,1,1 */
    #me,.you,p{
        color: black;
    }
</style>
<body>
    <div class="father">
        <div class="son">
            <div class="grandson">
                <h1 >工作室</h1>
            </div>
        </div>
    </div>
<hr>
    <table class="first" border="1" > 
        <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
            <td>4</td>
        </tr>
    </table>
<hr>
    <ul> 
        <li class="one">item0</li>
        <li class="two">item1</li>
        <li class="three">item2</li>
        <li class="four">item3</li>
        <li class="five">item4</li>
        <li class="six">item5</li>
        <li class="seven">item6</li>
        <li class="eight">item7</li>
    </ul>
<hr>
    <a href="">你好</a>

    <div id="b" class="a" >同类选择器</div>

    <p id="me" class="you">选择器个数</p>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值