[英]Less CSS - Additional rules for class when used on a specific element type
[英]Ignore CSS rules if in specific element
假设我有一个名为.root
的 class,其中包含大量适用于我几乎所有网站的 CSS 规则。
我还有一些“特殊”元素(包含在.root
元素中),但我不想将.root
规则应用于.special
元素中包含的任何内容。 我不想“覆盖”所有根规则,只是不应用它们。
是否可以只使用 CSS?
谢谢!
.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>
您可以使用 value property:initial
to one property 来获得该属性的初始值
或者您可以使用all: 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.