Why are my print styles not being rendered in IE 7 and IE 8?
Asked Answered
P

4

8

I have a webpage with 2 stylesheets being included:

<link rel="stylesheet" href="/assets/css/screen.css" type="text/css" media="all" />
<link rel="stylesheet" href="/assets/css/print.css" type="text/css" media="print" />

The print styles work just fine with chrome, safari, firefox, and IE9, but completely breaks in IE7 and IE8. Certain images that should be hidden are not, others that should be visible are not. It looks like a mess, despite the fact that if I load both stylesheets for screen in IE7 and IE8, everything looks exactly as I expect.

I'm unfortunately not able to link to the page, as it's a client site in progress, but I'm grasping at straws here if anyone has any ideas.

Pish answered 17/5, 2012 at 21:36 Comment(0)
P
14

Turns out, the problem was that HTML5 elements weren't rendering on print properly, and the HTML5 shiv doesn't support printing by default.

Luckily for me(and you), there's an IE print protection plugin made by Alexander Farkas over here: https://github.com/aFarkas/html5shiv

EDIT:

Looks like Modernizr now has a print shiv option if you're using Modernizr for all your shiv-ing (totally a word) needs: http://modernizr.com/download/

Pish answered 21/5, 2012 at 15:30 Comment(2)
I didn't use the script, but you were right: the IE8/7 where I was testing didn't support HTML5 elements when printing. +1 for that.Eastman
link to printshiv: github.com/aFarkas/html5shiv/blob/master/src/…Wellfixed
R
1

I think you need to denote the print styles as alternate...

<link rel="stylesheet" href="/assets/css/screen.css" type="text/css" media="all" />
<link rel="alternate stylesheet" href="/assets/css/print.css" type="text/css" media="print" />

Actually, I think that is wrong, but I am leaving it.

You may try changing the media attr for the print style to all and then wrapping everything inside the stylesheet in the print media query:

@media print { … }
Ramillies answered 17/5, 2012 at 21:40 Comment(0)
T
1

It's really a shot in the dark without seeing your css and markup, or at least a decent chunk of it!

There are issues with printing elements with position:absolute or fixed as noted in the comments to this msdn article; implying that you should manually reflow them (set position:static or possibly hide the elements completely). A hardcore way to deal with it would be adding

* {position:static !important;}

to your print.css; but its appropriateness would depend on page complexity and how you want it to be printed (i.e. just text, headers and a logo or a properly designed experience).

If you are not yet decided on the print experience you want to produce, consider reading another great article on alistapart focusing just on that!

Twoup answered 17/5, 2012 at 22:27 Comment(1)
Yeah, we already have the stylesheets designed and looking great in modern browsers, and everything seemed fine until IE8. Position: static does seem to have helped a little. The print logo is now visible whereas it was not before, but things are still unfortunately looking pretty wonky :(Pish
T
0

FYI I had this issue in IE9 and'alternate', i.e

<link rel="alternate stylesheet" href="......." type="text/css" media="print" />

worked for me in IE9 !

Tepic answered 10/3, 2014 at 2:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.