nth-child(1) 和 和 first-of-type的区别

nth-child() 是指该元素处在父级元素下不论标签的类型下排第几个

 

<section>
    <div>我是一个普通的div标签</div>         //第一个div儿子  表示 p:first-child      div:first-child或者 div:first-of-type  
    <p>我是第1个p标签</p>                   //第一个P儿子    表示 p:first-of-type    div:nth-child(2) 
    <p>我是第2个p标签</p>  <!-- 希望这个变红 -->  
    <div>我是一个普通的div标签</div> 
</section>

 

first-of-type 是指该元素处在父级元素下同种标签的第几个 

posted @ 2017-10-31 11:59  不乱来的嫖客  阅读(211)  评论(0编辑  收藏  举报