我有一些带有 display:none
设置的文本的 div。当我在屏幕上点击其他元素时,我有一个功能可以将其更改为 display:block
。
<div class="hiddenText" style="display:none">My hidden text</div>
我需要打印页面并显示所有文本。我为打印添加了 css 文件,并为隐藏文本指定了显示
@media print {
.hiddenText {
display: block
}
}
文档打印版本的所有样式都很好,除了这个。使其可打印的最佳方法是什么?
最佳答案
您的内联样式优先于其他地方指定的规则。要覆盖内联样式,您可以使用 !important
关键字来强制执行该规则。
像这样的东西可能会成功:
@media print {
.hiddenText {
display: block !important;
}
}
即使 !important
与 CSS 特异性无关,MDN 在 its article on the topic 中也有一个部分讨论 !important
。
When an !important rule is used on a style declaration, this declaration overrides any other declaration made in the CSS, wherever it is in the declaration list. Although, !important has nothing to do with specificity.
关于css - 不显示打印元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13711417/