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

兄弟選擇器 * + * 和 * ~ * 背后的邏輯是什么?

What is the logic behind sibling selectors * + * and * ~ *?(兄弟選擇器 * + * 和 * ~ * 背后的邏輯是什么?)
本文介紹了兄弟選擇器 * + * 和 * ~ * 背后的邏輯是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

對于這個問題,我使用以下標記:

<body><p>1</p><!-- 第1段--><p>2</p><!-- 第2段--><p>3</p><!-- 第 3 段 --></身體>

根據 .

解決方案

* + * 為從文檔根開始的任何元素的直接兄弟元素設置樣式 - 由于 <head> 實際上是正文的緊前同級(盡管在您的代碼中不可見),此選擇器針對正文和最后兩段,因為第一段不是緊跟在另一個同級元素之后.由于正常流程中塊級后代的 text-decoration 的性質,所有三個段落都加了下劃線.

* ~ * 這基本上和上面一樣,除了使用 通用兄弟組合器 .. 它設置出現在 <head> 之后的下游兄弟元素,無論它們是否是直接兄弟.由于 <body> 是唯一的兄弟,所以它與上面的選擇器具有相同的效果.由于繼承,第一段為斜體.

p ~ * 選擇一個 跟隨 <p> 的兄弟元素,在您的示例中是最后兩段.p + * 為段落的直接兄弟元素設置樣式,這也是最后兩個 <p> 元素.

For this question I'm using the following markup:

<body>
    <p>1</p> <!-- Paragraph 1 -->
    <p>2</p> <!-- Paragraph 2 -->
    <p>3</p> <!-- Paragraph 3 -->
</body>

From the Selectors Level 3 specification, the following selector rules apply:

*        any element
E + F    an F element immediately preceded by an E element
E ~ F    an F element preceded by an E element

Based on this, the following should occur:

body + * { } /* Selects nothing as no elements precede body */
body ~ * { } /* As above. */
p + *    { } /* Selects Paragraph 2 and Paragraph 3 as these are preceded by p */
p ~ *    { } /* As above. */
* + *    { } /* As above. */
* ~ *    { } /* As above. */

False!

* + * and * ~ * are somehow able to select Paragraph 1 along with 2 and 3! Paragraph 1 isn't preceded by anything, so should be impossible to access:

body + * { background: #000; }
body ~ * { background: #000; }
p ~ *    { color: #f00; }
p + *    { font-weight: bold; }
* + *    { text-decoration: underline; }
* ~ *    { font-style: italic; }

Result:

As you can see, paragraph 1 isn't preceded by the body or a phantom p, yet it is apparently preceded by something. It should have no custom styling applied to it at all, yet is somehow affected by those last two selectors. What is the logic behind this?

JSFiddle example.

解決方案

* + * Styles any element that is an immediate sibling of any element starting from the document root - Since the <head> is actually an immediate preceding sibling of the body (despite not being visible in your code) this selector targets the body and the last two paragraphs, since the first paragraph isn't immediately following another sibling element. All three paragraphs happened to be underlined due to the nature of text-decoration on block-level descendants in the normal flow.

* ~ * This is basically the same thing as above, except using the general sibling combinator .. it styles downstream sibling element(s) that appear after the <head> regardless of whether they're immediate siblings or not. Since the <body> is the only sibling, this has the same effect as the above selector. The first paragraph is italicized due to inheritance.

p ~ * selects a sibling element that is following a <p> which in your example is the last two paragraphs. p + * styles any element that is immediate sibling of a paragraph, which would also be the last two <p> elements.

這篇關于兄弟選擇器 * + * 和 * ~ * 背后的邏輯是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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热99re6国产在线播放 | 黄色大片视频 | 黄色网页免费 | 免费黄色小视频 | 日本中文在线观看 | 国产精品美女久久久 | 狠狠做深爱婷婷综合一区 | 国产成人a亚洲精品 | 午夜大片 | 成人激情在线观看 | www超碰| 天堂一区二区三区 | 国产精品久久久久久久久 | 一区二区精品视频 | 天天射日日干 | 国产精品久免费的黄网站 | 激情小说五月天 | 性欧美8khd高清极品 | 日本综合久久 | 日韩一区二区三 | 欧美又粗又长 | 日韩成人精品 | 国产乡下妇女做爰视频 | a级片在线免费观看 | 成人在线视频免费 | 在线观看日韩av | 手机成人在线视频 | 国产成人精品久久久 | 一本一道久久a久久精品蜜桃 | 一区二区三区高清 | 中文字幕在线免费播放 | 国产一级黄色大片 | 久久精品一区二区三区四区五区 | 一级特黄妇女高潮 | 国产成人在线免费观看 |