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

使用空格或大于號 >在 CSS 選擇器中?

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

問題描述

我有一些 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;
}

也會這樣做.

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

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

推薦答案

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

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>

所以在這里,有空格的選擇器將在父元素的任何嵌套級別定位 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;
}

<小時>

使用 >

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

而在這里,選擇器將定位到您的 div,它是具有 .welcome 的元素的 child,但它不會選擇div 嵌套在 section 標記內,因為它是外部 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;
}

<小時>

來自 MDN :(對于 ?)

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

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.

來自 MDN : (對于 >)

From MDN : (For >)

> 組合器分隔兩個選擇器并只匹配那些由第二個選擇器匹配的直接子元素第一個匹配的元素.相比之下,當兩個選擇器結合后代選擇器,組合選擇器表達式匹配由第二個選擇器匹配的那些元素存在與第一個選擇器匹配的祖先元素,與 DOM 上的躍點"數無關.

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.

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

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

相關文檔推薦

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
主站蜘蛛池模板: 欧美一区二区大片 | 国产第一区二区 | 亚洲精品小视频在线观看 | 欧美午夜一区二区三区免费大片 | 欧美一区二区三区四区视频 | 国产欧美精品一区二区 | 国产精品美女久久久久久免费 | 国产乱码精品一区二区三区五月婷 | 欧美黄色片 | 一区二区在线 | 99精品国自产在线 | 99精品久久99久久久久 | 五月天综合网 | 亚洲精品视频在线播放 | 国产精品一区二区在线播放 | 亚洲精品一区二区冲田杏梨 | 欧美xxxx色视频在线观看免费 | 中文字幕第十五页 | 欧美专区日韩专区 | 国产精品69毛片高清亚洲 | 天堂一区二区三区 | 亚洲免费视频网站 | 国产美女精品视频免费观看 | 人人爽人人草 | gav成人免费播放视频 | 欧美一级电影免费 | 国产欧美日韩一区二区三区 | 亚洲一区二区三区 | 免费成人av| 国产区第一页 | 日韩靠逼 | 91在线精品一区二区 | 久久不卡| 国产精品资源在线 | 国产一级片免费视频 | 精品免费av| 一二三在线视频 | 日韩1区| 成人免费日韩 | 亚洲精品久久久久中文字幕欢迎你 | 国产91丝袜在线18 |