久久久久久久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?)
主站蜘蛛池模板: 亚洲午夜av久久乱码 | 日韩av免费在线观看 | 国产精品有限公司 | 欧美成人精品一区二区三区 | 一区二区三区不卡视频 | 欧洲色综合 | 成人h免费观看视频 | 成人一区二区三区 | 亚洲国产成人久久久 | 91社影院在线观看 | 特级黄一级播放 | 国产精品久久久久久av公交车 | 欧美性jizz18性欧美 | 国产日韩一区二区三免费高清 | 国产真实精品久久二三区 | 亚洲国产成人在线视频 | 羞羞视频网站 | 污片在线观看 | 男女视频在线观看网站 | 91色在线| 91av免费看 | 亚洲一区欧美一区 | 日韩视频在线播放 | 亚洲视频精品在线 | 国产亚洲精品精品国产亚洲综合 | 黄色片网站国产 | 国产最好的av国产大片 | 精品99久久久久久 | 99久久久久久99国产精品免 | 999久久久国产精品 欧美成人h版在线观看 | 日韩精品免费在线观看 | 国产精品久久久久久久一区探花 | 午夜精品久久久久久久久久久久 | 久久久不卡网国产精品一区 | 少妇一级淫片免费播放 | 国产精品视频在线播放 | 国产成人精品一区二区三区四区 | 天天综合日日夜夜 | 成人性视频免费网站 | 日韩一区二区不卡 | 国产综合精品一区二区三区 |