VIPStephan
06-20-2007, 02:26 PM
Well, it’s not really a question that I have but an interesting observation I made and that I wanna share with you. I don’t have a blog to post that and receive comments so I’m doing it here. :)
Now here’s the case: Recently I got into writing print stylesheets and found that this seems to be an often neglected market segment. Anyway, I started to write the screen stylesheet as usual, then added a simple print stylesheet that hides all unnecessary stuff and just displays the relevant text. Looked all good except Safari gave me a headache because for some reason a big section of the top was just not displayed in the print preview (i.e. the text would be printed from the top of page one but it wouldn’t start with the header but rather somewhere in the middle of the text).
After a while I found that the dedicated screen stylesheet seems to have an influence on the print layout but only in Safari… strange.
I tracked it down to this rule (screen stylesheet):
#container {
width: 793px;
height: 629px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -315px;
margin-left: -396px;
border-top: 1px solid #173D81;
border-bottom: 1px solid #173D81;
}
As you can see I have a page that is absolutely centered. I’ve always been using this method so far and ha no problems with it - that was before I cared about print stylesheets.
Now what happens is that the top margin is somehow inherited to the print layout but only in Safari, resulting in parts of the content being moved upwards out of the page. And even trying to overwrite this rule and setting margin-top: 0; in the print stylesheet wouldn’t help. However, if I’m countermanding it through the positive value of 315px it’s displayed correctly - only in Safari print preview again, though. The others are now displaing a huge gap between the top of the page and the top of the text.
I racked my brain trying to find some kind of legal “hack” (as I care for validity) but nothing helped. However, finally I found a solution that is as simple as it can be, haha. :) A solution that makes one knock his head against the desk because it’s so simple. I just replaced the top property with bottom and the margin-top with margin-bottom, respectively, and TADAAA! It’s displayed correctly on paper/in print preview while still centering on the page (since it doesn’t matter which edge you use as reference to position it). :D
#container {
width: 793px;
height: 629px;
position: absolute;
bottom: 50%;
left: 50%;
margin-bottom: -315px;
margin-left: -396px;
border-top: 1px solid #173D81;
border-bottom: 1px solid #173D81;
}
Maybe someone before me found this already but I haven’t found anything on the internet so I thought I’d share my discovery to build up my ego by fishing for compliments and appreciative comments, haha. :p
Thanks for your attention.
Now here’s the case: Recently I got into writing print stylesheets and found that this seems to be an often neglected market segment. Anyway, I started to write the screen stylesheet as usual, then added a simple print stylesheet that hides all unnecessary stuff and just displays the relevant text. Looked all good except Safari gave me a headache because for some reason a big section of the top was just not displayed in the print preview (i.e. the text would be printed from the top of page one but it wouldn’t start with the header but rather somewhere in the middle of the text).
After a while I found that the dedicated screen stylesheet seems to have an influence on the print layout but only in Safari… strange.
I tracked it down to this rule (screen stylesheet):
#container {
width: 793px;
height: 629px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -315px;
margin-left: -396px;
border-top: 1px solid #173D81;
border-bottom: 1px solid #173D81;
}
As you can see I have a page that is absolutely centered. I’ve always been using this method so far and ha no problems with it - that was before I cared about print stylesheets.
Now what happens is that the top margin is somehow inherited to the print layout but only in Safari, resulting in parts of the content being moved upwards out of the page. And even trying to overwrite this rule and setting margin-top: 0; in the print stylesheet wouldn’t help. However, if I’m countermanding it through the positive value of 315px it’s displayed correctly - only in Safari print preview again, though. The others are now displaing a huge gap between the top of the page and the top of the text.
I racked my brain trying to find some kind of legal “hack” (as I care for validity) but nothing helped. However, finally I found a solution that is as simple as it can be, haha. :) A solution that makes one knock his head against the desk because it’s so simple. I just replaced the top property with bottom and the margin-top with margin-bottom, respectively, and TADAAA! It’s displayed correctly on paper/in print preview while still centering on the page (since it doesn’t matter which edge you use as reference to position it). :D
#container {
width: 793px;
height: 629px;
position: absolute;
bottom: 50%;
left: 50%;
margin-bottom: -315px;
margin-left: -396px;
border-top: 1px solid #173D81;
border-bottom: 1px solid #173D81;
}
Maybe someone before me found this already but I haven’t found anything on the internet so I thought I’d share my discovery to build up my ego by fishing for compliments and appreciative comments, haha. :p
Thanks for your attention.