html - CSS 未设置未按预期工作。如何解决?

标签 html css

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 而不是 initialunset

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.

MDN

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/

相关文章:

html - 容器中的中心div

html - CSS |向内的盒子阴影?

javascript - 触发器 i :active when keydown on HTML page

html - 负边距在 IE 中不起作用

css - 如何使灰色覆盖覆盖所有站点,包括帖子图像和元数据

html - 使用 Blogger API 获取的帖子数量限制(错误 400)

html - 如果 <html> 高度始终等于视口(viewport)的高度,为什么 <html> 内的底部定位页脚会移动到视口(viewport)下方

css 递增第 n 个子属性值

css - 如何在 text_field_tag 中添加图标

javascript - jquery animate scrollTop 无法在 FireFox 或 IE 上运行