css结构选择器,选择父元素中某一段元素

nth-of-type()和nth-child()写法一样,这里只用nth-of-type()演示,习惯type

直接上代码

 1         /* 从前向后选择,第6个开始 */
 2         li:nth-of-type(n+6){
 3             background: pink;
 4         }
 5         /* 从前向后选择,选择前6个 */
 6         li:nth-of-type(-n+6){
 7             background: blue;
 8         }
 9         /* 从后向前选择,倒数第6个结束 */
10         li:nth-last-of-type(-n+6){
11             background: red;
12         }
13         /* 选择第6个到第9个元素*/
14         li:nth-of-type(n+6):nth-last-of-type(n+6){
15             background: black;
16         }

猜你喜欢

转载自www.cnblogs.com/Mr-Car/p/10647674.html
今日推荐