第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

nth of-type vs nth-child

nth of-type vs nth-child

眼眸繁星 2019-07-08 12:44:15
nth of-type vs nth-child我有點困惑于第n個類型的偽類,以及它應該如何工作-特別是與第n個子類相比。也許我想錯了,但考慮到這個結(jié)構(gòu)<div class="row">     <div class="icon">A</div>     <div class="icon">B</div>     <div class="label">1</div>     <div class="label">2</div>     <div class="label">3</div></div>.第三個子元素(帶有類標簽的第一個元素)應該(也許?)可供選擇.row .label:nth-of-type(1) {     /* some rules */}但是,至少在這里的鉻,它沒有選擇它。它似乎只有當它是第一個孩子在行,這是相同的第n個孩子-因此,這和第n類型之間有什么區(qū)別?
查看完整描述

3 回答

?
Smart貓小萌

TA貢獻1911條經(jīng)驗 獲得超7個贊

這個nth-child偽類指的是“N個匹配的子元素”,意思是如果您有如下結(jié)構(gòu):

<div>
    <h1>Hello</h1>

    <p>Paragraph</p>

    <p>Target</p></div>

然后p:nth-child(2)將選擇也是p的第二個子級(即p加上“段”)。
p:nth-of-type將選擇第二個匹配p元素,(即我們的目標)p).

以下是ChrisCoyier@cs-Tricks.com關(guān)于這一主題的一篇偉大文章


您的類型中斷的原因是類型指元素的類型(即,div),但是第一個div與您提到的規(guī)則不匹配(.row .label),因此該規(guī)則不適用。

原因是css從右向左解析。,這意味著瀏覽器首先在:nth-of-type(1),確定它搜索類型的元素。div,這也是它的第一個類型,它與.row元素,以及第一個元素,.icon元素。然后,它將讀取元素應該具有.label類,它與上述任何內(nèi)容都不匹配。

如果要選擇第一個Label元素,則需要將所有標簽包裝在它們自己的容器中,或者只需使用nth-of-type(3)(假設總是有兩個圖標)。

另一種選擇(可悲的是)是使用.等著吧.。jQuery:

$(function () {
    $('.row .label:first')
        .css({
            backgroundColor:"blue"
        });});


查看完整回答
反對 回復 2019-07-08
?
胡說叔叔

TA貢獻1804條經(jīng)驗 獲得超8個贊

.label:nth-of-type(1)

此處“type”指的是元素的類型。在這種情況下,div不是去上課。這并不意味著第一個元素是.label,相反,它意味著其類型的第一個元素也有一個label.

類沒有任何元素。label在索引處1他們那種類型的。


查看完整回答
反對 回復 2019-07-08
?
叮當貓咪

TA貢獻1776條經(jīng)驗 獲得超12個贊

在圖中添加的10個元素中,有8個是<p>和2<i>,兩個陰影部分元素指示<i>其余8個是<p>

該頁面的CSS位于以下位置:

<style>
    * {
        padding: 0;
        margin:0;
    }
    section p {
        width: 20px;
        height: 20px;
        border:solid 1px black;
        border-radius: 15px;
        margin:20px;
        float: left;
    }
    section i {
        width: 20px;
        height: 20px;
        border:solid 1px black;
        border-radius: 15px;
        margin:20px;
        float: left;
    }
   section p:nth-child(1) {
        background-color: green; /*first-child of p in the flow*/
    }
   section i:nth-child(1) {
        background-color: red;  /*[first-child of i in the flow]NO */
    }
   section i:nth-of-type(1) {
        background-color: blue;  /*the type i of first child in the flow*/
    }
    </style></head><body>

    <section>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <i></i>
        <p></p>
        <i></i>
        <p></p>
        <p></p>
        <p></p>
    </section></body>

第一個綠色燈泡表示

 section p:nth-child(1) {
                background-color: green; /*first-child of p in the flow*/
            }

代碼中的第二個紅色燈泡不起作用,因為我不是流中的第一個元素。

section i:nth-child(1) {
            background-color: red;  /*[first-child of i in the flow]NO */
        }

圖中的藍色燈泡表示流動中的第一種類型的i。

section i:nth-of-type(1) {
            background-color: blue;  /*the type i of first child in the flow*/
        }


查看完整回答
反對 回復 2019-07-08
  • 3 回答
  • 0 關(guān)注
  • 419 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號