W3C home > Mailing lists > Public > www-style@w3.org > November 2004

[CSS21] Error in position:fixed and print medium

From: Syntactic: Jim Wilkinson <syntactic@btinternet.com>
Date: Mon, 22 Nov 2004 15:23:55 -0000
To: "www-style@w3.org" <www-style@w3.org>
Message-ID: <opshvg15ukbrj5zx@dial81-135-139-84.in-addr.btopenworld.com>

The question arises from time to time on CSS Discuss "Is there a CSS  
solution which would allow a header and footer to repeat on each printed  
page?". The usual suggestion is to make use of position:fixed, something  
like:-

@media print {
  div#printhead {
  display: block;
  position: fixed; top: 0; left: 0; width: 100%; height: 2em;
  }

I've researched the proposed solution based on this technique and, in a  
word, it doesn't work. I think the failure is not (just) in current  
browsers but in the spec. The method relies on the CSS description of  
position:fixed, namely "... In the case of the print media type, the box  
is rendered on every page, and is fixed with respect to the page ..."  
[Section 9.3.1].

Opera and Gecko-based browsers support position:fixed, so the header  
appears on every printed page. (IE doesn't support position:fixed at all,  
so the header appears at the top of the first page only.)

For the compliant browsers it's then necessary to shift down the  
document's main content on every page so that it doesn't overwrite the  
header. Setting a top margin on <body> (for example) will work only for  
the first page. I tried to figure out what the CSS2 spec authors had in  
mind. I concluded that the @page rule may have been intended here [Section  
13.2]. Setting an @page top margin creates a page-box margin on every page  
but unfortunately it shifts down the "fixed" header as well. So I then  
applied a negative "top" offset to it. Although that had the desired  
effect, the header, now shifted outside the <body> box, was hidden, even  
when I specified overflow:visible on <body>.

I've made no attempt to implement printed page footers.

No one on css-d has come up with a solution. It's my belief that the CSS21  
spec is deficient/inconsistent. Although we're talking about a very basic  
and practical item of functionality here, it may well be decided that  
CSS21 should not be amended since CSS3 Paged Media appears to address the  
issue through margin boxes [Section 4]. Can I ask a member of the CSS WG  
to comment on and acknowledge the issue?

-- 
Jim Wilkinson

Cardiff, Wales UK

Opera e-mail client: http://www.opera.com/m2/
Received on Monday, 22 November 2004 15:24:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:34 GMT