Print
only?

前端 未结 30 1986
暖寄归人
暖寄归人 2020-11-22 00:25

How do I print the indicated div (without manually disabling all other content on the page)?

I want to avoid a new preview dialog, so creating a new window with this

30条回答
  •  春和景丽
    2020-11-22 00:37

    In my case I had to print a image inside a page. When I used the solution voted, I had 1 blank page and the other one showing the image. Hope it will help someone.

    Here is the css I used:

    @media print {
      body * {
        visibility: hidden;
      }
    
      #not-print * {
        display: none;
      }
    
      #to-print, #to-print * {
        visibility: visible;
      }
    
      #to-print {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: auto;
        height: 99%;
      }
    }
    

    My html is:

    <%= image_tag @qrcode.image_url, size: "250x250" , alt: "#{@qrcode.name}" %>

提交回复
热议问题