伪类中序选择器的理解

最近复习基础,啃啃CSS权威指南,发现选择器相关知识点有些忽视和遗忘了,这里记录一下


1、伪类

:first-child,和 :first-of-type,
:last-child,和 :last-of-type

p:first-child
只选择是p标签且同层级中p为第一个时,才设置
p:first-of-type
选择同层级中所有p标签的第一个
last-child,last-of-type同理

child,孩子,所以先选出同层级的第几个,再判断是不是那个种类;of-type,种类,所以是同层级中同类型的第几个,其他的无视。
    <style type="text/css">
        p:first-child{
            color: red;
        }
        p:first-of-type{
            font-size: 30px;
        }
        p:last-child{
            color: green;
        }
        p:last-of-type{
            font-size: 5px;
        }
    </style>
</head>
<body>
    <div>第一层级的div</div>
    <p>第一层级的p1</p>
    <p>第一层级的p2</p>
    <div>
        <p>第二层级的p1</p>
        <p>第二层级的p2</p>
    </div>
</body>

在这里插入图片描述


:nth-child,和 :nth-of-type

同上理解:
在这里插入图片描述


:nth-last-child(); 和 :nth-last-of-type()

同上理解
在这里插入图片描述


:only-child

同上理解
在这里插入图片描述

2、odd奇数,even偶数

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值