CSS: @media print without external css file?

不打扰是莪最后的温柔 提交于 2019-12-25 00:58:07

问题


I want to print a html page in a specific way under css. But all the @media print examples seem to have an external .css file I want to be able to do it without an external file which means there will be no link rel tag:

 <LINK REL="stylesheet" MEDIA="print...

How do I do this?


回答1:


I would suggest using an external stylesheet but you can how ever do this on the same page as your HTML if you really want to, an example of this would be like so,

HTML / CSS

<!DOCTYPE html>
<html>
    <head>
         <style>
              @media print {

                   /* changes the display property to none on all 
                      p elements when printed */
                   p { display: none}
              }
         </style>
    </head>
    <body>
         <p>I'm here when the page isn't printed</p>
    </body>
</html>



回答2:


Use the @media print query in a CSS style block:

<style>
@media print {
   /* print css here */
}
</style>



回答3:


Make sure your closing style tag () has a space between the end of the @media print query and the closing tag. Like so:

@media print {
      stuff {more stuff;}
} </style>

Right curly bracket, space, then closing tag.



来源:https://stackoverflow.com/questions/19533186/css-media-print-without-external-css-file

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