How to only show certain parts with CSS for Print?

后端 未结 6 655
悲&欢浪女
悲&欢浪女 2020-11-27 20:22

I have a page with lots of data, tables and content. I want to make a print version that will only display very few selected things.

Instead of writing another page

6条回答
  •  时光取名叫无心
    2020-11-27 20:29

    I got here because I was curious about printing a chart generated by chart.js. I wanted to just print the chart directly from the page (with a button that does a 'window.print') without all of the other content of the page.

    So, I got closer by using the technique from the answer here: Why can't I override display property applied via an asterisk? .

    You have to apply the 'asterisk' to the 'body' element, not just by itself. So, using the example CSS that the OP (Nathan) added to the question, I changed it to this:

    
    

    Then adding that 'printable' class to the chart itself, as in

    
    

    Which removed all page elements on the printed output except the chart when the 'print' button is clicked (via this):

    
    

    So, perhaps this will help anyone that gets to this question via the googles.

提交回复
热议问题