欢迎光临散文网 会员登陆 & 注册

css 控制子元素

2022-11-03 11:23 作者:听书的胖子  | 我要投稿

这个用来调整第一个元素

:first-child{background:#ff0000;}


这个用来控制指定元素

:nth-child(3){background:#ff0000;}


也可以这样写
:nth-child(3n){background:#ff0000;}


控制最后一个

:last-child{background:#ff0000;}

倒着数第二个,也是可以这样控制的
:nth-last-child(2){background:#ff0000;}


这个是说第二个指定元素

(PS:上面的是第二个元素,以下为第二个指定元素,注意,不一样的。)

p:nth-of-type(2) { color: red; }

css 控制子元素的评论 (共 条)

分享到微博请遵守国家法律