码迷,mamicode.com
首页 > Web开发 > 详细

CSS的nth-of-type和nth-child的区别

时间:2018-10-04 10:25:03      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:red   utf-8   info   alt   分享   class   oct   技术   计算   

<!--源代码-->
<!
DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> div{ width: 100px; height: 100px; background: #ff11ff; } p{ width: 100px; height: 100px; background: blue; } /*div:nth-child(2n+1){*/ /*background: red;*/ /*}*/ div:nth-of-type(2n+1){ background: red; } </style> </head> <body> <div></div> <div></div> <p></p> <div></div> <div></div> </body> </html>

 

使用nth-child的效果图:                        使用nth-of-type:效果

技术分享图片                                                                                               技术分享图片

从上面可以看到:nth-child是从父元素的第一个子元素算起走,会算其他标签元素,而nth-of-type只会计算父元素下本标签元素

 

CSS的nth-of-type和nth-child的区别

标签:red   utf-8   info   alt   分享   class   oct   技术   计算   

原文地址:https://www.cnblogs.com/alex-xxc/p/9739579.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!