CSS3中first-child、last-child、nth-child、nth-last-child

1.单独指定第一个子元素、最后一个子元素的样式css

<style type="text/css">spa

li:first-child{ast

  background:yellow;样式

}co

li:last-child{background

   background:blue;

}

</style>

 

2.对指定序号的子元素使用样式

<style type="text/css">

li:nty-child(2){

  background:yellow;

}//对第二个子元素设定背景色

li:nth-last-child(2){

  background:blue;

}//对倒数第二个子元素设定背景色

</style>

 

3.对全部第偶数个子元素或者第奇数个子元素使用样式

<style type="text/css">

li:nth-child(odd){

  background:yellow;

}

li:nth-child(even){

 background:blue

}

</style>

相关文章
相关标签/搜索