久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用空格或大于號(hào) >在 CSS 選擇器中?

Use a space or greater than sign gt; in CSS selector?(使用空格或大于號(hào) gt;在 CSS 選擇器中?)
本文介紹了使用空格或大于號(hào) >在 CSS 選擇器中?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有一些 CSS 代碼:

I have some CSS code:

.welcome div {
   font-size: 20px;
}

它做我想做的事,但也寫得像

which does what I want it to do, but also writing it like

.welcome > div {
   font-size: 20px;
}

也會(huì)這樣做.

是否有任何理由使用一種而不是另一種,或者它們只是做同一件事的兩種不同方式?

Is there any reason to use one over the other or are they just two different ways of doing the same thing?

推薦答案

不,它們完全不同,使用 > 選擇子元素,而使用空格將選擇任何級(jí)別的嵌套元素.

No they are completely different, using > selects a child element whereas using a space will select a nested element at any level.

例如……

在選擇器中使用 ?/space…

Using ?/space in the selector…

<div class="welcome">
    <section>
        <div>This will be selected</div>
    </section>
    <div>This will be selected as well</div>
</div>

所以在這里,有空格的選擇器將在父元素的任何嵌套級(jí)別定位 div.

So here, the selector having space will target the div at any nested level of the parent element.

演示 (使用<代碼>?/空格)

.welcome div {
    font-size: 20px;
    color: #f00;
}

<小時(shí)>

使用 >

<div class="welcome">
    <section>
        <div>This won't be selected</div>
    </section>
    <div>This will be selected</div>
</div>

而在這里,選擇器將定位到您的 div,它是具有 .welcome 的元素的 child,但它不會(huì)選擇div 嵌套在 section 標(biāo)記內(nèi),因?yàn)樗峭獠?div 的孫子(但不是子).

Whereas here, the selector will target your div which is a child of the element having .welcome but it won't select the div which is nested inside section tag as it is a grandchild (but not a child) of the outer div.

演示 2 (使用 >)

.welcome > div {
    font-size: 20px;
    color: #f00;
}

<小時(shí)>

來(lái)自 MDN :(對(duì)于 ?)

? 組合子(用于表示空格或更多一個(gè)或多個(gè)空白字符)組合了兩個(gè)選擇器這樣組合的選擇器只匹配那些匹配的元素有祖先元素匹配的第二個(gè)選擇器第一個(gè)選擇器.后代選擇器類似于 child選擇器,但它們并不要求它們之間的關(guān)系匹配的元素是嚴(yán)格的父子元素.

The ? combinator (that's meant to represent a space, or more properly one or more whitespace characters) combines two selectors such that the combined selector matches only those elements matching the second selector for which there is an ancestor element matching the first selector. Descendant selectors are similar to child selectors, but they do not require that the relationship between matched elements be strictly parent-child.

來(lái)自 MDN : (對(duì)于 >)

From MDN : (For >)

> 組合器分隔兩個(gè)選擇器并只匹配那些由第二個(gè)選擇器匹配的直接子元素第一個(gè)匹配的元素.相比之下,當(dāng)兩個(gè)選擇器結(jié)合后代選擇器,組合選擇器表達(dá)式匹配由第二個(gè)選擇器匹配的那些元素存在與第一個(gè)選擇器匹配的祖先元素,與 DOM 上的躍點(diǎn)"數(shù)無(wú)關(guān).

The > combinator separates two selectors and matches only those elements matched by the second selector that are direct children of elements matched by the first. By contrast, when two selectors are combined with the descendant selector, the combined selector expression matches those elements matched by the second selector for which there exists an ancestor element matched by the first selector, regardless of the number of "hops" up the DOM.

這篇關(guān)于使用空格或大于號(hào) &gt;在 CSS 選擇器中?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

CSS selector when :target empty(:target 為空時(shí)的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒(méi)有任何價(jià)值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結(jié)果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯(cuò)誤:當(dāng)使用 JS 刪除項(xiàng)目時(shí),first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對(duì)多個(gè) HTML 標(biāo)簽使用相同的 ID?)
主站蜘蛛池模板: wwwxxx欧美 | 日日夜夜精品 | 在线国产视频 | 精品欧美一区二区精品久久 | 黄色免费网站 | 黄色录像一级片 | 久在线观看| 三级av网站 | 中国1级毛片 | 日韩精品免费在线观看 | av大全在线观看 | 成人a级片| 亚洲精品美女 | 国产精品欧美一区二区 | 天天天天天干 | 黄色片视频网站 | 国产精品久久久久久久免费看 | 黄色一级大片在线免费看国产一 | 99久久精品一区二区成人 | 国产精品成人一区二区三区 | 国产日韩欧美亚洲 | 999毛片| 中文字幕免费视频 | 伊人久久艹| 艳妇乳肉豪妇荡乳 | 国产成人av网站 | 亚洲国产欧美日韩在线 | 亚洲不卡在线观看 | 96视频在线 | 精品视频免费 | 一级国产片| 高h乱l高辣h文短篇h | 成人免费看片39 | 午夜免费网站 | 红桃视频成人 | 日韩精品久久久久久 | 久久av资源| 国产理论在线观看 | 在线观看黄色小视频 | 国产精品2区| 日本加勒比在线观看 |