html - 为什么 !important 在 CSS 中不起作用?

标签 html css

我想在我的网站中将所有字体大小放大到 200%,here are some test code in fiddle ,

如果真的是 PX 问题,但如果我在“<-h2>”中添加样式,为什么这里的代码可以正常工作?

<div  >
<h2 class="test" style="font-size:300% !important">
hello
</h2>
<h2 class="test2">
hello
</h2>
<h2 class="test3">
hello
</h2>

或者,还有一个问题,如何以相同的比例放大所有字体大小?

最佳答案

使用 em 和 rem。

您可以使用这个 http://pxtoem.com/

HTML

<div style="font-size:2rem !important" >
    <h2 class="test">
    hello
    </h2>
    <h2 class="test2">
    hello
    </h2>
    <h2 class="test3">
    hello
    </h2>
</div>

CSS

.test{
  font-size:1em;
}
.test2{
  font-size:2em;
}
.test3{
  font-size:3em;
}

工作 fiddle :https://jsfiddle.net/eom40w0L/8/

关于html - 为什么 !important 在 CSS 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39199513/

相关文章:

html - 如何创建带有双白色底边框的输入?

html - 如何在窗口浏览器底部展开页脚

html - 制作特定宽度列的 HTML 表格

jquery - Chrome 误读最大高度和最大宽度

c# - 使用面板 asp/css 框内有 4 个框的框

css - Chrome 中的百分比行轨道和装订线警告

javascript - jQuery 元素显示并在按钮单击时向下滑动

html - 将 Selenium 指向某些输入,无法弄清楚xpath,css选择器等

javascript - Fabric.js 便签类型文本换行

javascript - 将左向屏幕外导航栏转换到屏幕右侧的问题