CSS选择器复习

选择器优先级

选择器优先级
继承或*0 0 0 0
标签选择器

0 0 0 1

类选择器或伪类选择器0 0 1 0
id选择器0 1 0 0
行内样式1 0 0 0
!important无穷大
复合选择器叠加但不进位

 

HTML代码

<!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>Document</title>
    <style>
        /* 通配符选择器 */
        * {
            margin: 0;
            padding: 0;
        }

        /* 标签选择器 */
        h1 {
            color: red;
        }

        /* 类选择器 */
        .blue {
            color: skyblue;
        }

        /* id选择器 */
        #four {
            color: orange;
        }

        /* 后代选择器 */
        .hot ul li a {
            color: pink;
        }

        /* 子选择器 */
        .hot>a {
            color: rgb(68, 228, 148);
        }

        /* 并集选择器 */
        h1,
        .hot {
            background-color: #666;
        }

        /* 伪类选择器 */
        /* 链接伪类选择器 */
        .test a:link {
            color: pink;
        }

        .test a:visited {
            color: red;
        }

        .test a:hover {
            background-color: skyblue;
        }

        .test a:active {
            background-color: orange;
        }

        input:focus {
            background-color: pink;
        }
    </style>
</head>

<body>
    <h1>h1标题 标签选择器 red类</h1>
    <h2 class="blue">h2标题 类选择器</h2>
    <h3 class="blue">h3标题 类选择器 可以同时选中我和h2</h3>
    <h4 id="four">h4标题 id选择器</h4>
    <div class="hot">
        <a href="#">大肘子</a>
        <ul>
            <li><a href="#">猪头</a></li>
            <li><a href="#">猪尾巴</a></li>
        </ul>
    </div>
    <ul class="test">
        <li><a href="#">link:pink</a></li>
        <li><a href="#">visited:red</a></li>
        <li><a href="#">hover:bgc_skyblue</a></li>
        <li><a href="#">active:orange</a></li>
    </ul>
    <input type="text" value="表单标签">
</body>

</html>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值