2017-02-20 23 views
7

開始選擇I類要選擇不含一類具有z-depth-開頭的子元素:不以字符串

<div class="well"> 
    <div class="well"></div> 
</div> 

因此,如果內。好了還含有一類像z-depth-1它將不會被選中。

這是不工作,因爲內部。好總是選擇:

.well .well:not([class^="z-depth-"]) 

是,即使可能嗎?

+2

'.well:not([class^=「z-depth - 」])'如果第一類是'z-depth- *' – pol

+1

「這不起作用」並不是一個真正的問題聲明。向我們展示一個演示問題的例子會更好,而不是讓回答者(如下面的謝爾蓋)彌補您可能面臨的問題。 –

+0

「不工作」是問題的「你有什麼嘗試」部分。前面的句子已經說明了這個問題。 – rzb

回答

5

不能選擇不包含與z-depth-開始CSS,你只能一類的子元素:

  1. 選擇所有的子元素,其class屬性值

.well .well:not([class^="z-depth-"]) { 
 
    color: red; 
 
}
<div class="well z-depth-1">Parent div 
 
    <div class="z-depth-2 well">First child div</div> 
 
    <div class="well z-depth-3">Second child div</div> 
 
</div>
:不要 z-depth-子開始

  • 選擇所有的子元素,其class屬性的值不包含z-depth-子:
  • .well .well:not([class*="z-depth-"]) { 
     
        color: red; 
     
    }
    <div class="well z-depth-1">Parent div 
     
        <div class="z-depth-2 well">First child div</div> 
     
        <div class="well z-depth-3">Second child div</div> 
     
        <div class="well">Third child div</div> 
     
    </div>

    你也可以詳細瞭解MDN上的所有CSS選擇器。

    +0

    沒有辦法針對孩子。特別是? – rzb

    +0

    @RegularEverydayNormalGuy最後一個例子針對孩子'.well',你是什麼意思? –

    +1

    我已經更新瞭解釋它的更好的問題。感謝您迄今的努力。 – rzb

    2

    您將需要結合^=*=以獲得所需的結果。

    .well:not([class^="z-depth-"]) { /*will ignore elements if the first class is z-depth-* */ 
     
        background-color: lightgreen; 
     
    } 
     
    .well:not([class*=" z-depth-"]) { /*will ignore elements if z-depth-* is second class or later */ 
     
        background-color: skyblue; 
     
    }
    <div class="z-depth-1 well">z-depth-1 well</div> 
     
    <div class="well z-depth-1">well z-depth-1</div>

    下面是關於如何使用屬性選擇一個nice guide

    +0

    你的答案和選定的答案一起幫助我指出了正確的方向。這確實是我對「^」符號的理解。 '.well .well:not([class * =「z-depth - 」])'工作。也謝謝你。 – rzb