views:

28

answers:

2

I have a website, and I need to have an image centered at the bottom of the visible page. So in any screen size, the image will still be at the bottom, and centered.

A: 

using pure css you can achieve this in all new browsers

    .fix{
    position:fixed;
    bottom:0px;
    left:50%;
    }
<img src="yourimagepath" class="fix"/>

and for IE6 you can use position:absolute; instead of fixed. it will position the image on the bottom of the page but as you scroll up the image will scroll with the page. unfortunately position:fixed in not supported in IE6

Pankaj Kumar
IF position:absolute works, why bother using position:fixed in newer browsers?
xandy
@xandy: Fixed is the position of an object in relation to the browser window.Absolute is the position of an object in relation to its containing element
Pankaj Kumar
@shawn: i saw ur code. try using ARR class on the image inside the div and not on the div
Pankaj Kumar
ok I'll try that.
Shawn
Pankaj Kumar, I put the code:.ARR{ position:fixed; bottom:0px; left:50%; }But it's still not centered
Shawn
@Shawn use an outside div that has `bottom: 0px; left: 0px; right: 0px; text-align: center` and put the image in there without any additional CSS. That should center it.
Pekka
Pankaj Kumar I see the problem was not factoring the image's width into the centering
Shawn
A: 

You should put it into a div and then, imagining your image is 500px wide:

div.className{
position:absolute;
margin-left: -250px; /* very important for the image to be centered */
left:50%;
bottom:0px;
}
fmsf