【问题标题】:how to overwrite inline styles in print css?如何覆盖打印 CSS 中的内联样式?
【发布时间】:2011-05-09 10:46:16
【问题描述】:

我知道,内联样式是“邪恶的”,但是在 html 中插入了 javascript(jQuery 动画)。那么,有可能吗?

【问题讨论】:

  • 打印网页会渲染JS吗?抱歉,只是一个问题并没有太大帮助 - 没想到会...
  • 我不是,但是当页面加载时,会执行js并添加样式。所以当我打印页面时,这些样式仍然在 dom 中

标签: javascript jquery css printing overriding


【解决方案1】:

这个:

  <div style="background: red;">
        The inline styles for this div should make it red.
    </div>

可以被覆盖:

div[style] {
   background: yellow !important;
}

您可以将!important 添加到任何css 属性

【讨论】:

  • 我认为内联样式不能被覆盖,即使是 !important?
  • attr 选择器和 !important 的组合是关键。
【解决方案2】:

尝试将 !important 放在打印样式表中的值和分号之间:

body {
    background-color: #0f0 !important;
}

【讨论】:

  • 确实可以,但是要覆盖某些浏览器中的样式,您需要使用 attr 选择器,ie6 不支持该选择器
猜你喜欢
  • 1970-01-01
  • 2016-12-17
  • 1970-01-01
  • 1970-01-01
  • 2017-11-03
  • 2013-05-24
  • 2010-10-02
  • 1970-01-01
  • 2020-12-03
相关资源
最近更新 更多