Printing html ignores CSS stylesheets

陌路散爱 提交于 2020-01-02 02:17:07

问题


I have a very simple html page with a table element.

The document is styled with 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? In my case it would be the same.. Is that really necessary?


回答1:


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. The all media type will work across web and print. However, if you wanted to explicitly state another stylesheet for print than replace the all with print.

  • Check to see if the style are not being overridden by something else. As CSS is Cascading Style Sheets
  • Get Firebug.



回答2:


If your stylesheet link has media="screen", then it will be ignored by print. In that case you can create a separate print stylesheet with media="print" or just change your existing style sheet to media="all".




回答3:


The media attribute is used to determine the stylesheet purpose. You need to make sure that it is set to all (for all purposes) or print (only used when printing).



来源:https://stackoverflow.com/questions/3957974/printing-html-ignores-css-stylesheets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!