码迷,mamicode.com
首页 > 其他好文 > 详细

nth-child和nth-of-type

时间:2016-08-12 18:11:27      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

<section>
    <div>我是一个普通的div标签</div>
    <p>我是第1个p标签</p>
    <p>我是第2个p标签</p>  <!-- 希望这个变红 -->
</section>

p:nth-child(2){color:red;} ---选择其父节点下的第二个元素,并且该元素是p 标签                            p:nth-of-type(2){color:red;} ---选择其父节点下的第二个元素

预览:                                                                                                                               预览:

    技术分享                                                                                 技术分享

 

 使用nth-of-type 会比较好些,比较直观

 

nth-child和nth-of-type

标签:

原文地址:http://www.cnblogs.com/haigui-zx/p/5765756.html

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