html怎么增加兄弟元素,html – 只有当CSS中有Y兄弟时,我如何定位最后N个兄弟元素?...

到目前为止,最简单的方法是使用自己的一组伪类来定位要设置样式的2个元素.

正如你所说,最后一个孩子由3n 8(8,11,14 ……)代表.然后,倒数第二个孩子是3n 7(7,10,13 ……).

li:nth-last-child(1):nth-child(3n+8),

li:nth-last-child(2):nth-child(3n+7) {

color: red;

}

ul { counter-reset: item; list-style-type: none; }

li { display: inline; padding: 0.25em; }

li::before { content: counter(item); counter-increment: item; }

您也可以使用一个复杂的选择器,使用Can CSS detect the number of children an element has?中的技术,用3n 8代替:nth-​​last-child()参数,并使用额外的:nth-​​last-child(-n 2)来定位最后两个具有一个伪类的元素:

li:first-child:nth-last-child(3n+8) ~ li:nth-last-child(-n+2) {

color: red;

}

ul { counter-reset: item; list-style-type: none; }

li { display: inline; padding: 0.25em; }

li::before { content: counter(item); counter-increment: item; }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值