Fixing width issues with IE6 print stylesheets
categories: css
Note to self: remember to use !important when trying to deal with text running off the page in print versions of pages in IE6.
Basic steps to follow:
- EITHER have separate print and screen stylesheets ...
<link rel="stylesheet" media="screen" type="text/css" href="styles.css" /> <link rel="stylesheet" media="print" type="text/css" href="print.css" />
- ... OR declare separate screen and print rule sets in a single stylesheet
@media print { #foo { display:none; } } @media screen { #foo { display:block; } }
- Put the content that you do want printed in containers that you can easily target with a CSS rule. Then, in the print css,
display:noneall the siblings of the containers that don't need to be printed. It may take a little trial and error to get the lists of printing and non-printing elements right, but well-designed, semantic HTML can make this task easier. Long story short, if you candisplay:nonea parent element, you don't need to alsodisplay:noneits children. The flipside of that is that if you dodisplay:nonea parent, you can't thendisplay:[anything]children elements to get them to show up. - To deal with IE issues, give a fixed width to the containers you do want printed, and make the width
!important:#content { width:400px !important; /* 400px seems to work well if you want to span the width of a letter-sized page */ }
- Also to deal with IE issues, you may find it useful to put some
padding-righton yourpelements. - If you have print rules that are required for IE but break things in other browsers, use a conditional comment to include the rules in a separate stylesheet.
Further reading:
These are just some notes; interested in hearing other's tips!

March 21st, 2008 at 7:34 am
The CSS approach looks simple at the first sight.
But id DOES NOT WORK ALWAYS.
If you adjust a rule using javascript, the CSS info is ignored.
on the page http://www.rakovszky.eu/?Literature/Favourites.shtml
the index-block can be hidden/shown by double-clicking in the “Sizer-bar”.
The ratio between the index and poems blocks can be csanged by clicckin on the sizer-bar, moving it and then fix it by another click.
Unluckily this can be only achieved by setting the marginLeft rule for the poetry-box.
In wain do I specify for the media a left-margin of 10px, it is ignored.
I have spent a long time experimenting with floating blocks and table-columns, but without success.
MSR