How can i apply CSS to print?

前端 未结 4 939

I am trying to print a div in one of my pages but i can\'t apply css when printing. Writing media=\"print\" inside of the style tags doesn\'t work. What should i do?

4条回答
  •  萌比男神i
    2021-01-16 18:55

    What you're doing in your original message will work fine. It's just the old school way of doing things.

    One thing to note is that the browser will not apply all of your styles in the print mode. It picks and chooses which styles are print appropriate. I have also found that if you use a HTML 5 doctype it will give you slightly different results.

    Here's a simple example similar to yours that you can try in the browser.

    
    
    
    
    
    
    
    Print This?
    Another Style

    Here's a screenshot from the print preview of Chrome (v19.0.1077.3 canary), which you mentioned your using to test this.

    enter image description here

提交回复
热议问题