show div only when printing

后端 未结 8 2187
清歌不尽
清歌不尽 2020-12-19 02:01

Let\'s say that I have

Title

Printing content

相关标签:
8条回答
  • 2020-12-19 02:27

    You need media query for switching between print and screen option

    @media screen { /* for screen option*/
    
    p {
    
          font-family: verdana, sans-serif;
    
          font-size: 17px;
    
      }
    
       }
    

    @media print { /* for print option*/

     p {
    
         font-family: georgia, serif;
         font-size: 14px;
         color: blue;
       }
    
      } 
    

    http://www.w3schools.com/css/css_mediatypes.asp

    0 讨论(0)
  • 2020-12-19 02:33

    I think the best solution would be to create a wrapper around the non-printable stuff:

    <head>
        <style type="text/css">
    
        #printable { display: none; }
    
        @media print
        {
            #non-printable { display: none; }
            #printable { display: block; }
        }
        </style>
    </head>
    <body>
        <div id="non-printable">
            Your normal page contents
        </div>
    
        <div id="printable">
            Printer version
        </div>
    </body>
    
    0 讨论(0)
提交回复
热议问题