可以配合 li 标签使用,选择一列中的哪些标签。
1.first-child 选择列表中的第一个标签
2. last-child 选择列表中的最后一个标签
li:first-child{color:red}
li:last-child{color:pink}
3.nth-child(n)
这里的n为数字,表示选择列表中的第n个标签
例如选择第三个标签
li:nth-child(3){color:pink}
4.nth-child(2n)
选择列表中的偶数,选中 2、4、6…… 个标签。
li:nth-child(2n){color:pink}
li:nth-child(2n-1){color:pink}
5.同理.nth-child(2n-1)就表示选中了奇数位标签
6.选择从第4个到最后一个标签,这个4可以提换成你需要的数字
li:nth-child(n+4){color:pink}
7. 选择从第一个到第四个 这里的数字4也是可以根据你的需要替换的。
li:nth-child(-n+4){color:pink}
8.nth-last-child(3) 表示最后三个标签
li:nth-last-child(3){color:pink}
9.nth-last-child(3n) 表示3的倍数3.6.9……
li:nth-last-child(3n){color:pink}
10.nth-last-child(3n-1) 表示2.5.8…… 可以用这个设置等差数列的样式
li:nth-last-child(3n-1){color:pink}
希望有帮到你。
本文深入讲解CSS中的选择器,包括:first-child、:last-child、:nth-child(n)、:nth-child(2n)、:nth-child(2n-1)、:nth-child(n+4)、:nth-child(-n+4)、:nth-last-child(3)、:nth-last-child(3n)和:nth-last-child(3n-1),并展示了如何通过这些选择器精确地定位和样式化列表中的特定元素。
&spm=1001.2101.3001.5002&articleId=107945335&d=1&t=3&u=dc70ec4299964d1fbc29efb627959af0)
1251

被折叠的 条评论
为什么被折叠?



