首页 > Web开发 > 详细

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

时间:2016-09-03 12:22:16      阅读:209      评论:0      收藏:0      [点我收藏+]

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

<style type="text/css">

li:first-child{

  background:yellow;

}

li:last-child{

   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>

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

原文:http://www.cnblogs.com/wyaocn/p/5836555.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!