I’m using this CSS to vertically center a sprite:
#content {
width:750px;
height:950px;
position:absolute;
left:50%;
top:50%;
margin:-475px 0 0 -375px;
}
…when the height of the browser window is less than 950px I lose the top of my image.
How could I set the image to center vertically when the browser height is greater than 950px, but when it’s less, the top of the image remains fixed and I only lose the bottom part?
I’m already using links in my source code to switch between css style sheets based on screen size such as this:
<link rel="stylesheet" media="screen and (min-width:481px) and (max-width:800px)"
href="tablet.css" />
but as I understand it, you can’t switch style sheets based in browser height.
The most simple way to center the image vertically (and in the example also horizontally) could be this approach:
Hope this is the behavior you’d expected
DEMO
http://jsfiddle.net/uB3pW/
HTML
CSS
Note
Won’t work in IE7.