css 控制子元素
2022-11-03 11:23 作者:聽(tīng)書(shū)的胖子 | 我要投稿
這個(gè)用來(lái)調(diào)整第一個(gè)元素
:first-child{background:#ff0000;}
這個(gè)用來(lái)控制指定元素
:nth-child(3){background:#ff0000;}
也可以這樣寫(xiě)
:nth-child(3n){background:#ff0000;}
控制最后一個(gè)
:last-child{background:#ff0000;}
倒著數(shù)第二個(gè),也是可以這樣控制的
:nth-last-child(2){background:#ff0000;}
這個(gè)是說(shuō)第二個(gè)指定元素
(PS:上面的是第二個(gè)元素,以下為第二個(gè)指定元素,注意,不一樣的。)
p:nth-of-type(2) { color: red; }
標(biāo)簽: