一·伪元素的介绍

<!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>
    <style>
        ul>li::before{
            /*  */
            content: "";
            /* display:设置元素的性质 */
            width: 50px;
            height: 2px;
            /* 设置背景颜色 */
            background-color: yellow;
            display: block;
        }
       
        ul>li::after{
            /* 设置元素内容 */
            content: "";
            /* display:设置元素的性质 */
            width: 50px;
            height: 2px;
            /* 设置背景颜色 */
            background-color: red;
            display: block;
        }
       
       
    </style>
</head>
<body>
    <!-- 伪元素:通过css设置元素=》一般用于实现某些效果,但是直接添加在html中会打乱结构
          ::before=》在...之前添加元素
          ::after=》在...之前添加元素
        注意:伪元素选择器必须与content属性一起使用-->
    <ul>
        <li>
            lorem1</li>
        <li>lorem2</li>
        <li>lorem3</li>
    </ul>
</body>
</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>伪选择器t</title>
    <style>
        /* 效果是鼠标悬停在p、a的字体变成红色 */
        p:hover>a{
            /* 选择鼠标悬停的对象是p时,设置样式作用的对象是a */
            color: red;
        }
        p{
            width: 200px;
            height: 40px;
            background-color: green;
        }
        .text:link{
            color: aqua;
        }
        .text:valid{
            color: black;
        }
        .text:hover{
            color: red;
        }
        .text:active{
        color: blueviolet;
        }
        
    </style>
    <!--:link=》未访问时
        :hover=》设置鼠标悬停时的样式 ,所有元素都可以使用
        :active=》鼠标按下为松开,其他元素也是可以的
        :visiited=》鼠标松开,被访问时 
    顺序::link>:visited>:hover>:active-->
</head>
<body>
    <p class="text">xvssbxxfb
        <!-- <a href="#">勇找吴法。</a> -->
    </p>
    <a href="#" class="text">以兼自是通。</a>
    <a href="#">以卑不</a>
</body>
</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>复合选择器</title>
    <!-- 复合选择器:多个选择器组合来选中一个元素
        交集:选择器选中了相同的元素. =》重点优先级
    并集 -->
    <style>
        #afirst {
            color: brown;
        }
        ul>.first #afirst{
            color: aqua;
        }
    </style>
</head>
<body>
    <ul>
        <li class="first">
            <p><a href="#" id="afirst">lorem1</a></p>
        </li>
        <li>
            <p><a href="#" id="asecond">lorem2</a></p>
        </li>
        <li>
            <p><a href="#">lorem3</a></p>
        </li>
        <li>
            <p><a href="#">lorem4</a></p>
        </li>
    </ul>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

第六天MW

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值