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

鄰接的 CSS 選擇器

CSS Selector for Adjacency(鄰接的 CSS 選擇器)
本文介紹了鄰接的 CSS 選擇器的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

似乎 CSS 是右關(guān)聯(lián)的,并且與編程語(yǔ)言不同,您不能用括號(hào)來(lái)影響它.

我有這個(gè)一般結(jié)構(gòu):

<div class='pizza'></div></div><p>選擇我!選擇我!</p>

<div class="披薩"><p>不要選擇我!</p></div></div>

我無(wú)法找出一個(gè) <p> 的選擇器,該選擇器跟隨一個(gè)包含 <div class=" 的兄弟 <div>比薩">.

我試過(guò)這個(gè),但 CSS 的從右到左的關(guān)聯(lián)性并沒(méi)有產(chǎn)生我想要的:

div >div.pizza + p

我知道這是不對(duì)的.

有人可以指點(diǎn)一下嗎?

解決方案

組合器,至少是目前可用的組合器,只能表達(dá)兩個(gè)元素之間的關(guān)系.正如您正確觀察到的那樣,您無(wú)法更改組合子的關(guān)聯(lián)性.正因?yàn)槿绱?,而且沒(méi)有父元素對(duì)應(yīng)于子元素的 > 組合子,所以不可能構(gòu)造一個(gè) CSS 選擇器來(lái)表示 both

div >div.pizza

div + p

每個(gè)選擇器中的第一個(gè) div 代表相同的元素.

這個(gè)關(guān)聯(lián)性問(wèn)題可以使用建議的 :has() 偽類來(lái)解決,它在功能性偽類中為您提供了相對(duì)選擇器語(yǔ)法,允許您將這樣的選擇器構(gòu)造為

div:has(> div.pizza) + p

其中 p 是最外層選擇器的主題.相對(duì)選擇器 >div.pizza 是 范圍 到第一個(gè) div 選擇器——本質(zhì)上,這是上面前兩個(gè)復(fù)雜選擇器的組合,:has() 偽類的作用與任何其他簡(jiǎn)單選擇器一樣.

目前尚不清楚這個(gè)提議的功能是否會(huì)在 CSS 中實(shí)現(xiàn).

查看我對(duì)這些相關(guān)問(wèn)題的回答以了解更多信息:

  • CSS 選擇器中是否允許使用括號(hào)?
  • 如何使用CSS根據(jù)頁(yè)面中另一個(gè)元素的狀態(tài)選擇一個(gè)元素?

It seems CSS is right associative, and unlike programming languages, you cannot influence this with parentheses.

I have this general structure:

<div>
   <div class='pizza'></div>
</div>
<p>Select me!  Select me!</p>

<div>
   <div class="pizza">
      <p>Do NOT select me!</p>
   </div>
</div>

I can't figure out the selector for a <p> that follows a sibling <div> containing a <div class="pizza">.

I tried this but the right-to-left associativity of CSS does not yield what I want:

div > div.pizza + p

I know this isn't right.

Can someone offer a pointer?

解決方案

Combinators, at least the ones that are currently available, can only express a relationship between exactly two elements. As you've correctly observed, you cannot change the associativity of combinators. Because of this, and the fact that there is no parent counterpart to the > combinator for child elements, it is not possible to construct a CSS selector that represents both

div > div.pizza

and

div + p

where the first div in each selector represents the same element.

This associativity issue can be solved using the proposed :has() pseudo-class, which provides you with a relative selector syntax within a functional pseudo-class, allowing you to construct such selectors as

div:has(> div.pizza) + p

where p is the subject of the outermost selector. The relative selector > div.pizza is scoped to the first div selector — essentially, this is a combination of both of the first two complex selectors above, with the :has() pseudo-class acting just like any other simple selector.

It is not known yet if this proposed feature will be implemented in CSS.

See my answers to these related questions for more info:

  • Are parentheses allowed in CSS selectors?
  • How do I select an element based on the state of another element in the page with CSS?

這篇關(guān)于鄰接的 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?)
主站蜘蛛池模板: 日韩激情在线 | 欧美视频1| 日韩一二区在线观看 | 老司机成人在线 | 91精品国产91久久久久久密臀 | 精品欧美一区二区三区久久久 | 精品国产乱码久久久久久老虎 | 国产激情91久久精品导航 | 中文字幕 在线观看 | 日韩成年人视频在线 | 国产在线播放av | 国产精品美女久久久久aⅴ国产馆 | 国产精品亚洲一区 | 一级黄色大片 | 可以免费观看的av | 99re在线视频| 男人午夜视频 | 国产成人jvid在线播放 | 免费久久网站 | 亚洲欧美一区二区三区视频 | 久久网亚洲 | 毛片久久久 | 国产片一区二区三区 | 久久久久久久91 | 国产成人精品久久二区二区91 | 超碰97人人人人人蜜桃 | 日日操夜夜操视频 | 国产精品99精品久久免费 | 久久99精品久久久久久 | 成人午夜激情 | 亚洲欧美一区二区三区视频 | 超碰在线播 | 精品网 | 亚洲一二三区免费 | 欧美激情精品久久久久久变态 | 欧美一级大黄 | 丁香色婷婷 | 日本一二三区在线观看 | 国产乱码精品一区二区三区中文 | 欧美日韩精品综合 | 国产精品免费一区二区三区 |