views:

76

answers:

2

I need to be able to center the image vertically for all the common resolutions. A lot of ppl here on SO have already asked this question before, and 90% of then give this tutorial http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

as an answer. However, when viewed at my 1280 by 1024 res monitor in FF, it's not centered. And worse yet, it breaks horribly in IE7. So, it's definitely NOT the answer.

Am I chasing the impossible dream? The solution has to work for FF and IE 6/7

the solution can be anything that would work, though being a bit of a purist, I would prefer a div over table:)

specifically i need it for this site http://www.codecookery.com/test/index.html

as you see, it's a slideshow, that needs to be centered.

A: 

If a fixed-height div is an option then you can use position absolute with top 50% and then use a negative margin to position the div. I tested the following in FF3.6, IE6, IE8 and Chrome.

<html>
<head>
  <style>
    #vertCenter {
        height: 400px; 
        position: absolute; 
        top: 50%; 
        margin-top: -200px;
        border: 1px green solid;
    }
  </style>
</head>

<body>
  <div id="vertCenter">
        any text<br>
        any height<br>
        any content, for example generated from DB<br>
        everything is vertically centered
  </div>
</body>
</html>
Sam
A: 

The code here is less horrible than that of jakpsatweb.cz.

reisio