views:

95

answers:

4

I am trying to position a div (footer) element at the bottom of a printed page. In firefox this is working fine and the div will sit along the bottom of the printed page.

However, in Safari the footer moves up the printed page if the browser window is not very tall. eg. if the browser window is 200px tall then the footer sits on the print out about 200px down. If the browser is 400px tall it draws the footer 400px down the page.

I would like to get the same behaviour in Safari as I can get in Firefox if possible?

The basic code I am using for this is:

<html>
    <head>
        <title>Print footer at bottom of a printed page</title>
        <style type="text/css">
            * { margin:0; padding:0; }
            html, body { height: 100% !important; }
            #footer { height:25px; border-top:solid 1px #000;
                      position:absolute; bottom:0; }
        </style>
    </head>
    <body>
        <p>Some content on the page here</p>
        <div id="footer">This should appear at the very bottom of the printed page</div>    
    </body>
</html>

Edit: I'm happy if the solution requires a hack...it only needs to work in Safari

A: 

You could try using position:fixed instead, but I'm not sure it's quite the effect you're looking for.

Litso
Unfortunately 'fixed' gives the same (wrong) behaviour
Richard
A: 

CSS doesn't make this easy. There's a whole bunch of ways to achieve this, but they tend to be very hacky, or else (as you've found) not work in all browsers.

The best solution I've found has been is at CSSStickyFooter.com, which seems to be pretty good in all respects.

hope that helps.

Spudley
Nope...it sits up the middle of the page too
Richard
@Richard: Are you sure? I just opened the cssstickyfooter.com page in Safari, and it looks fine, with the footer stuck to the bottom of the browser as intended. (Safari v5.0.2, but I'm quite sure it worked in earlier versions too when I tried it previously)
Spudley
I think the problem is the printed page, not the view page.
Mauro
Sorry...I didn't make it very clear in the original post. I am looking to position is at the bottom of a printed page (ie. On A4 paper). It works correctly on screen but when you print it the footer sits at about the height its at in the browser so the print out resembles what you see on screen. Unfortunately this is not the bottom of the print out where I want the footer to show up.
Richard
Ah, that explains. I misunderstood you, sorry.
Litso
Ah right. I missed that in the question. Hmm... that might be tricky. CSS does have some print-specific functionality, which may help you (google [css @print](http://www.google.com/search?q=css+%40print)), but footer positioning is hard enough in the browser window, let alone in print which browser makers put so much less effort into.
Spudley
A: 

I just printed this out in Chrome (same rendering engine as Safari), and the line showed at the bottom...

<!DOCTYPE html> 
<html> 
  <head> 
    <title>Testing</title> 
    <style type="text/css" media="print">
      html, body { margin: 0; padding: 0; }
      body { height: 11in;  width: 8.5in; }
      #footer { position: absolute; bottom: 0; }
    </style> 
  </head> 
  <body> 
    <div id="footer"> 
      This will always print at the bottom
    </div> 
  </body> 
</html>

Notice that I have media="print" on the style tag. For more on this, read Going to Print on ALA.

Josh Stodola
Thanks. I didn't realise you could specify a size in terms of inches / cm.
Richard
@Richard Absolute units in CSS: http://www.w3.org/TR/css3-values/#absolute0
Josh Stodola
A: 

Have you tried this version?

http://www.themaninblue.com/experiment/footerStickAlt/

I know it works in browsers, but not sure about print.

Alex