在其他地方使用 print.css 和 @media print
我有一个网页,它使用站点全局 print.css 样式表来呈现页面以进行打印。该页面还使用 div、标题等站点范围的类。
我需要在打印版本中增加正文的宽度和该页面的字体大小。我无权编辑全局 print.css,并且不想在那里进行更改,因为这些更改会影响我不想更改的其他页面(由于使用全局样式、div 类、 ETC。)。
幸运的是,该页面确实有自己的样式表 foo.css,我可以对其进行编辑以进行仅影响该页面的更改。
更复杂的是,该页面在主体类上有内联样式,我只需要更改打印样式。
通常我会用我的样式更改来编辑 foo.css,使用 !important 根据需要覆盖内联样式,但我不明白的是:
- 我可以使用 @media print { body {width: 900px; } !important;}} 在 foo.css 中并让它工作,即使我已经有一个 print.css?
我一直在尝试在 Firebug(使用 Web 开发人员工具栏)中对此进行测试,但是如果我将 @media print 调用添加到 foo.css,似乎什么也没有发生。
想法?
I've got a webpage that uses a site global print.css stylesheet to render the page for print. The page also uses sitewide classes for divs, headers, etc.
I need to increase the width of the body and the size of the font of this page in the print version. I don't have access to edit the global print.css, and would prefer not to make my changes there because the changes will affect other pages that I don't want to change (due to the use of global styles, div classes, etc.).
Fortunately, this page does have its own stylesheet, foo.css that I can edit to make changes that will only affect this page.
Further complicating this is that the page has an inline style on the body class that I need to change for print only.
Normally I would edit foo.css with my style change, using !important to override the inline style as needed, but what I can't figure out is:
- Can I use @media print { body {width: 900px; !important;}} in foo.css and have it work even though I already have a print.css?
I've been trying to test this in Firebug (with Web Developer Toolbar), but if I add the @media print call to foo.css, nothing seems to happen.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该是可能的。要检查的事项:
all
媒体是否包含 foo.css?!important
之前不应该有;
。您的
@media
选择器的特异性是否高于内联样式?This should be possible. Things to check:
is foo.css included with
all
media?You shouldn't have a
;
before!important
.Does your
@media
selector have higher specificity than the inline style?