如果在特定元素中则忽略 CSS 规则
假设我有一个名为 .root
的类,其中包含大量 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>
Let's say I have a class called .root
which contains a lot of CSS rules which applies to almost all of my website.
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. I don't want to "override" all root rules, just not apply them.
Is it possible using only 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用值
property:initial
到一个属性来获得该属性的初始值,或者您可以使用
all:initial
将选择器的所有值设置为其初始值值https://developer.mozilla.org/fr/docs/Web/CSS /首字母
you can use value
property:initial
to one property to the have the initial value of this propertyor you can use
all: initial
to set all value of a selector to their inital valuehttps://developer.mozilla.org/fr/docs/Web/CSS/initial