CSS3 选择前几个元素 选择后几个元素等问题
生活随笔
收集整理的這篇文章主要介紹了
CSS3 选择前几个元素 选择后几个元素等问题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//例如有如下代碼塊
<div><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p>
</div>1.選擇第n個p
div:nth-child(n)
p:nth-of-type(n)2.選擇倒數(shù)第n個p
div:nth-last-child(n)
p:nth-last-of-type(n)3.選擇偶數(shù)
div:nth-child(2n)
p:nth-of-type(2n)?4.選擇奇數(shù)
div:nth-child(2n - 1)
p:nth-of-type(2n - 1)5.選擇前幾個元素 例: 前4個p
div:nth-child(-n + 4)
p:nth-of-type(-n + 4)6.選擇從第4個元素開始之后的元素
div:nth-child(n + 4)
p:nth-of-type(n + 4)7.選擇第2-第5個元素
//5和6兩者結(jié)合使用,可以限制選擇某一個范圍
div:nth-child(-n + 5):nth-child(n + 2)
p:nth-of-type(-n + 5):nth-of-type(n + 2)
?
?
?
總結(jié)
以上是生活随笔為你收集整理的CSS3 选择前几个元素 选择后几个元素等问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 编译时类型 和运行时类型的 区别(1)
- 下一篇: CSS 基本样式