[英]Ignore CSS rules if in specific element
Let's say I have a class called .root
which contains a lot of CSS rules which applies to almost all of my website.假设我有一个名为
.root
的 class,其中包含大量适用于我几乎所有网站的 CSS 规则。
I also have some "special" elements (included in the .root
one), but I don't want to apply the .root
rules to whatever is included in .special
elements.我还有一些“特殊”元素(包含在
.root
元素中),但我不想将.root
规则应用于.special
元素中包含的任何内容。 I don't want to "override" all root rules, just not apply them.我不想“覆盖”所有根规则,只是不应用它们。
Is it possible using only CSS?是否可以只使用 CSS?
Thank you!谢谢!
.root { color: blue; /* Lots of other styles */ }.special { font-weight: bold; }
<div class="root"> This is blue <div class="special"> <span>This is bold and blue, but I'd like this to be only bold</span> </div> </div>
you can use value property:initial
to one property to the have the initial value of this property您可以使用 value
property:initial
to one property 来获得该属性的初始值
or you can use all: initial
to set all value of a selector to their inital value或者您可以使用
all: initial
将选择器的所有值设置为其初始值
https://developer.mozilla.org/fr/docs/Web/CSS/initial https://developer.mozilla.org/fr/docs/Web/CSS/initial
.root { color: blue; /* Lots of other styles */ }.special { font-weight: bold; color: initial; }
<div class="root"> This is blue <div class="special"> <span>This is bold and blue, but I'd like this to be only bold</span> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.