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

CSS:不是偽類不起作用

CSS :not pseudo-class not working(CSS:不是偽類不起作用)
本文介紹了CSS:不是偽類不起作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在學習 :not() 偽類,但它沒有按預期工作.

我想將除 .mind 之外的所有文本都涂成紅色.出于某種原因,這并不能阻止 .mind 元素變紅.

:not(.mind) {紅色}

<div class='parent'><div class='child'>一個</div><div class='child'>兩個</div><div class='child'>三個</div><div class='child'>一個</div><div class='child'>兩個</div><div class='child'>三個</div><div class='child'>一個</div><div class='mind'>mind</div><div class='child'>三個</div><div 類='孩子'><p>第一段</p></div></div>

解決方案

記住這一點:

:not() 等價于 *:not()

:not() 偽類前面沒有選擇器時,隱含一個通用選擇器:

<塊引用>

測試此行為的快速方法是使用不可繼承的 border 屬性.

在下面的示例中,使用您的選擇器,您會注意到邊框沒有應用到 .mind,并且您的選擇器按預期工作:

:not(.mind) {紅色;邊框底部:1px 虛線黑色;}

<div class='parent'><div class='child'>一個</div><div class='child'>兩個</div><div class='child'>三個</div><div class='child'>一個</div><div class='child'>兩個</div><div class='child'>三個</div><div class='child'>一個</div><div class='mind'>mind</div><div class='child'>三個</div><div 類='孩子'><p>第一段</p></div></div>

為了您的特定目標:

<塊引用>

我想將除 .mind 之外的所有文本都涂成紅色.

使用更具體的選擇器.

.parent >:沒關系) {紅色;}

<div class='parent'><div class='child'>一個</div><div class='child'>兩個</div><div class='child'>三個</div><div class='child'>一個</div><div class='child'>兩個</div><div class='child'>三個</div><div class='child'>一個</div><div class='mind'>mind</div><div class='child'>三個</div><div 類='孩子'><p>第一段</p></div></div>

I am learning about the :not() pseudo class and it is not working as expected.

I want to color all text red except for .mind. For some reason this is not preventing the .mind element from being red.

:not(.mind) {
  color: red
}

<div class='parent'>
  <div class='child'>One</div>
  <div class='child'>Two</div>
  <div class='child'>Three</div>
  <div class='child'>One</div>
  <div class='child'>Two</div>
  <div class='child'>Three</div>
  <div class='child'>One</div>
  <div class='mind'>mind</div>
  <div class='child'>Three</div>
  <div class='child'>
    <p>First paragraph</p>
  </div>
</div>

解決方案

Keep this in mind:

:not() is equivalent to *:not()

When there is no selector prefixing the :not() pseudo-class, a universal selector is implied:

6.2. Universal selector

If a universal selector represented by * (i.e. without a namespace prefix) is not the only component of a sequence of simple selectors selectors or is immediately followed by a pseudo-element, then the * may be omitted and the universal selector's presence implied.

Therefore, the rule you have:

:not(.mind) {
  color: red
}

... is saying apply red color to all elements except the element with the class mind.

Okay, except in this case, the color property is inheritable, so even though the red doesn't get applied to the .mind element, it still gets the red through inheritance from the .parent element.

Here's what the browser is doing:

A quick way to test this behavior is with the border property, which is not inheritable.

In the example below, using your selector, you'll notice that the border doesn't get applied to .mind, and your selector works as you were expecting:

:not(.mind) {
  color: red;
  border-bottom: 1px dashed black;
}

<div class='parent'>
  <div class='child'>One</div>
  <div class='child'>Two</div>
  <div class='child'>Three</div>
  <div class='child'>One</div>
  <div class='child'>Two</div>
  <div class='child'>Three</div>
  <div class='child'>One</div>
  <div class='mind'>mind</div>
  <div class='child'>Three</div>
  <div class='child'>
    <p>First paragraph</p>
  </div>
</div>

To your particular objective:

I want to color all text red except for .mind.

Use a more specific selector.

.parent > :not(.mind) {
  color: red;
}

<div class='parent'>
  <div class='child'>One</div>
  <div class='child'>Two</div>
  <div class='child'>Three</div>
  <div class='child'>One</div>
  <div class='child'>Two</div>
  <div class='child'>Three</div>
  <div class='child'>One</div>
  <div class='mind'>mind</div>
  <div class='child'>Three</div>
  <div class='child'>
    <p>First paragraph</p>
  </div>
</div>

這篇關于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精品免视看婷婷 | 毛片站| 日韩精品在线视频免费观看 | 欧美一级艳情片免费观看 | 成人综合在线视频 | 久久欧美高清二区三区 | 久久国产综合 | 超碰网址| 日日摸夜夜添夜夜添特色大片 | 国产盗摄视频 | 久草.com| 蜜臀网 | 91香蕉| 色www精品视频在线观看 | 91n成人| 日本三级日产三级国产三级 | 日本在线精品视频 | 蜜月aⅴ国产精品 | 亚洲欧美一区二区三区国产精品 | 伊人性伊人情综合网 | 国产一区二区美女 | 青青久在线视频 | 91精品国产综合久久久久久丝袜 | 国产专区在线 | 亚州精品天堂中文字幕 | caoporn免费在线视频 | 美日韩免费视频 | 亚洲国产精品一区二区久久 | 日韩国产欧美一区 | 激情三区 | 日本中文在线 | 精品国产欧美 | 精品亚洲永久免费精品 | 亚州一区二区三区 | 色橹橹欧美在线观看视频高清 | 在线观看中文字幕视频 | 性色av一区二区三区 | 青青伊人久久 | 97国产精品| 欧美精品一区二区在线观看 |