<css3-子类型选择器>

23 篇文章 0 订阅

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 儿子类型选择器 -->
    <style type="text/css">
        /*从p类型标签中开始选,不考虑前面的其他类型标签
        会从每一个父容器中寻找一个

        */
        p:first-of-type {
            background: orange;
        }

        /*从最后一个开始找*/
        p:last-of-type {
            background: greenyellow;
        }

        /*偶数个*/
        p:nth-of-type(even) {
            border: 5px solid #000;
        }

        /*奇数*/
        p:nth-of-type(odd) {
            border: 5px solid red;
        }

        /*指定某一个*/
        p:nth-of-type(3) {
            background: black;
        }

        /*使用公式计算*/
        p:nth-of-type(3n+1) {
            line-height: 50px;
        }

        /*使用其他属性*/
        .item:nth-of-type(2n+2) {
            background: green;
        }
    </style>
</head>
<body>
    <div>
        <h1>h1</h1>
        <img src="#" alt="#">
        <p class="item">1-1</p>
        <p class="item">2-2</p>
        <p class="item">3-3</p>
        <p class="item">4-4</p>
        <p class="item">5-5</p>
        <p class="item">6-6</p>
        <p class="item">7-7</p>
        <p class="item">8-8</p>
        <p class="item">9-9</p>
        <p class="item">10-10</p>
        <h3 class="item">1-1</h3>
        <h3 class="item">2-2</h3>
        <h3 class="item">3-3</h3>
        <h3 class="item">4-4</h3>
        <h3 class="item">5-5</h3>
    </div>
    <div>
        <p class="item">1-1</p>
        <p class="item">2-2</p>
        <p class="item">3-3</p>
        <p class="item">4-4</p>
        <p class="item">5-5</p>
        <p class="item">6-6</p>
        <p class="item">7-7</p>
        <p class="item">8-8</p>
        <p class="item">9-9</p>
        <p class="item">10-10</p>
    </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值