css - 关于nth-child()的问题
ringa_lee
ringa_lee 2017-04-17 11:45:36
[CSS3讨论组]

span:nth-child(-n+3)
匹配前三个子元素中的span元素
为什么是匹配前3个元素??如果n是0开始的话,不应该是n+3吗?

ringa_lee
ringa_lee

ringa_lee

全部回复(2)
天蓬老师
  1. span:nth-child(n+3) 感觉是匹配的从第三个往后的所有 span 元素

  2. n 应该是从 0,1,2,…… 加上负号才能保证 nth-chlid(里面的数字小于等于三)

怪我咯

Example:

-n+6 / represents the first 6 elements of the list /

The values of A and B can be negative, but only the positive results of An+B, >for n ≥ 0, are used.

你可以这样理解,n是从0开始计数(0,1,2...)
所以(-n+6) => (6,5,4,3,2,1)所以是前六个
上面的引用已经说了,只有正数会被使用。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号