css 高大上选择器:nth-child() 应用实例

WBOY
リリース: 2016-06-01 09:53:12
オリジナル
1338 人が閲覧しました

前端的哥们想必都接触过css中一个神奇的玩意,可以轻松选取你想要的标签并给与修改添加样式,是不是很给力,它就是“:nth-child”。

下面我将用几个典型的实例来给大家讲解:nth-child的实际用途:

Tips:还用低版本的IE浏览器的哥们请绕过!

 

:nth-child(2)选取第几个标签,“2可以是你想要的数字”

<code class="language-css">.demo01 li:nth-child(2){background:#090}</code>
ログイン後にコピー

 

:nth-child(n+4)选取大于等于4标签,“n”表示从整数,下同

<code class="language-css">.demo01 li:nth-child(n+4){background:#090}</code>
ログイン後にコピー

 

:nth-child(-n+4)选取小于等于4标签

<code class="language-css">.demo01 li:nth-child(-n+4){background:#090}</code>
ログイン後にコピー

 

:nth-child(2n)选取偶数标签,2n也可以是even

<code class="language-css">.demo01 li:nth-child(2n){background:#090}</code>
ログイン後にコピー

 

:nth-child(2n-1)选取奇数标签,2n-1可以是odd

<code class="language-css">.demo01 li:nth-child(2n-1){background:#090}</code>
ログイン後にコピー

 

:nth-child(3n+1)自定义选取标签,3n+1表示“隔二取一”

<code class="language-css">.demo01 li:nth-child(3n+1){background:#090}</code>
ログイン後にコピー

 

:last-child选取最后一个标签

<code class="language-css">.demo01 li:last-child{background:#090}</code>
ログイン後にコピー

 

:nth-last-child(3)选取倒数第几个标签,3表示选取第3个

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!