當(dāng)其父級(jí)具有特定類別時(shí),我需要覆蓋子級(jí)顏色。.parent { width: 100%;}.parent>.child { color: black;}.parent>.child.blue { color: blue;}.parent.error { color: red !important;}.parent.error>.child { color: red !important;}<div class="parent"> <div class="child">Child #1</div> <div class="child blue">Child #2</div></div>當(dāng)使用 jquery 添加父類時(shí)出現(xiàn)“錯(cuò)誤”時(shí)$('.parent').addClass('error'),只有Child #1顏色變?yōu)榧t色。2 號(hào)孩子(班上有額外的藍(lán)色<div class="child blue">Child #2</div>)保持藍(lán)色。問(wèn)題是,如何強(qiáng)制Child #2將其顏色更改為紅色而不指定.parent.error > .child.blue錯(cuò)誤類別。/*If this style is added, it will work*/.parent.error > .child.blue { color: red !important;}謝謝...
指定特定類時(shí)強(qiáng)制 div 子級(jí)文本顏色
繁華開(kāi)滿天機(jī)
2023-10-30 19:57:55