web前端

这篇博客探讨了CSS中的nth-child和nth-of-type选择器的区别,以及它们在实际布局中的应用。同时,详细解释了伪元素::before和::after的用法,并通过实例展示了如何在元素前后插入内容。
摘要由CSDN通过智能技术生成

<!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>

        /* 区别nth-child   nth-of-child */

        /* nth-child 会把所有盒子都排序号

        执行的时候先看 :nth-child(1) 之后回去看前面的div */

        section li:nth-child(1){

            background-color: rebeccapurple;

        }

          /* nth-child 会把指定的盒子都排序号

        执行的时候先看 :nth-child(1) 之后回去看前面的div */

        section li:nth-of-type(1){

            background-color: red;

        }

        div {

            width: 200px;

            height: 200px;

            background-color: pink;

        }

        /* 伪元素 在文本中找不到 */

        div::before {

            /* content必须要写 */

            content: '我是';

        }

        div::after {

            content: '爸爸';

        }

    </style>

</head>

<body>

    <section>

        <p>大宝</p>

        <li>熊大</li>

        <li>熊二</li>

    </section>

    <div>

        光头强

    </div>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值