nth-child(n)和nth-of-type(n)
生活随笔
收集整理的這篇文章主要介紹了
nth-child(n)和nth-of-type(n)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
:nth-child(n):父元素的子元素的第n個
:nth-of-type(n):父元素的 某類 子元素的第n個
注:n從0起,元素index從1起
nth-child(n)和nth-of-type(n)例:
<head><style>body :nth-child(2) {height: 30px;background: blue;color: #fff;}</style> </head> <body><p>1 - p1</p><div>2 - div1</div><p>3 - p2</p><div>4 - div2</div> </body>替換 :nth-child 為 :nth-of-type
<style>body :nth-of-type(2) {height: 30px;background: blue;color: #fff;} </style>總結
以上是生活随笔為你收集整理的nth-child(n)和nth-of-type(n)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: webpack3的CommonsChun
- 下一篇: 小程序小知识备忘