I all: unset
取消所有继承属性但允许用户代理样式表。我该怎么做?正如您在代码中看到的那样,它禁用了所有样式,甚至是用户代理样式表。如何防止禁用用户代理样式表?
h1, h2 {
color: red;
font-size: 24px;
font-weight: bold;
}
.editor_data * {
all: unset;
}
<div class="main_block">
<h2>Should be red</h2>
<div class="editor_data">
<h1><u><em><strong>Should be underlined, bold, italics, but not red</strong></em></u></h1>
</div>
</div>
最佳答案
尝试使用关键字 revert
而不是 initial
或 unset
The revert keyword is useful for isolating embedded widgets or components from the styles of the page that contains them, particularly when used with the all property.
In user stylesheets, revert rolls back the cascade and resets the property to the default value established by the user-agent stylesheet.
h2 {
color: red;
font-size: 24px;
font-weight: bold;
}
.editor_data * {
all: revert;
}
<div class="main_block">
<h2>Hello world!</h2>
<div class="editor_data">
<h1><u><em><strong>Hello world!</strong></em></u></h1>
</div>
</div>
关于html - CSS 未设置未按预期工作。如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55651739/