簡體   English   中英

將CSS屬性應用於類,但僅當元素具有另一個特定的類時

[英]Apply CSS properties to class but only if element has another specific class

我有這個HTML:

 <li class="arrow branches"></li>
 <li class="arrow branches"></li>
 <li class="arrow branches"></li>

 <li class="arrow"></li>
 <li class="arrow"></li>
 <li class="arrow"></li>

我只想為“箭頭分支”類提供css命令,如何給它們提供不會影響“箭頭”類的css?

創建類.branches

.branches{
    color:#f00;
}

如果要僅將其應用於具有分支和箭頭的元素,則將它們放在一起:

.arrow.branches{
    color:#f00;
}

但是,如果您想將其應用於多個類,這也很容易:

.branches, .otherClass{
    color:#f00;
}

這非常簡單:

li.arrow.branches
{...styles...}

這將選擇具有類分支AND箭頭的LI元素,但不能單獨選擇arrow元素。

.arrow.branches { // your css }

僅適用於兩個類的元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM