简体   繁体   English

打印html会忽略CSS样式表

[英]Printing html ignores CSS stylesheets

I have a very simple html page with a table element. 我有一个非常简单的带有表元素的html页面。

The document is styled with css. 该文档采用CSS设计。 When I print the page it looks like there are no stylesheets at all. 当我打印页面时,看起来根本没有样式表。 Wrong font, everything is wrong. 字体错误,一切都错了。

What's the problem here? 这有什么问题? Do I have to create a special css only for printing? 我是否必须仅为打印创建一个特殊的CSS? In my case it would be the same.. Is that really necessary? 在我的情况下它会是相同的..这真的有必要吗?

Without the link to the page, I can only offer little advice. 如果没有页面链接,我只能提供一些建议。

  • Make sure the link to the stylesheet in the header is correct. 确保标题中样式表的链接正确无误。 And it should look something like this: 它应该看起来像这样:

    <link rel="stylesheet" type="text/css" href="/link/to/.css" media="all">

I just noticed that you mentioned print . 我刚注意到你提到了print The all media type will work across web and print. all媒体类型都可以在Web和打印中使用。 However, if you wanted to explicitly state another stylesheet for print than replace the all with print . 但是,如果要显式声明另一个用于print样式表,请将all替换为print

  • Check to see if the style are not being overridden by something else. 检查样式是否未被其他内容覆盖。 As CSS is Cascading Style Sheets 因为CSS 层叠样式表
  • Get Firebug. 获得Firebug。

If your stylesheet link has media="screen" , then it will be ignored by print. 如果样式表链接具有media="screen" ,则打印将忽略它。 In that case you can create a separate print stylesheet with media="print" or just change your existing style sheet to media="all" . 在这种情况下,您可以使用media="print"创建单独的打印样式表,或者只将现有样式表更改为media="all"

The media attribute is used to determine the stylesheet purpose. media属性用于确定样式表的用途。 You need to make sure that it is set to all (for all purposes) or print (only used when printing). 您需要确保将其设置为all (用于所有目的)或print (仅在打印时使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM