Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Horizontal & Vertical Centering of Div's
I need to know if this is possible for a div to be horizontally and vertically centered on a page, WITHOUT know the width and height of the page before hand.
I know it is possible with CCS, BUT, it only works in Safari.
Does anyone know of a JS way to do this? I would really appreciate your help.
Thanks heaps.
0
This discussion has been closed.
Comments
.divClassName { margin-left: auto; margin-right: auto; }
vertical;
much more tricky. i haven't found a good way of doing it. i'm sure you can do it in javascript, but i'm not too handy with javascript.
#horizon {
position: absolute;
top: 50%;
left: 0px;
width: 100%;
margin-top: -50px;
min-width: 330px;
}
Then putting the image in the centre. Admittedly, my friend did it for me. Have a look at the source of the front page of my site
http://www.bambambambambam.co.uk to see how it works.
Propably the easiest way to do that is with JS, or possibly with DHTML, I saw it done once, but it was alot of doohikeys.
But you might want to test something like this
position:absolute; margin:-100px 0px 0px -200px; top: 50%; left: 50%;
Thanks should really go to the user epohs who's here sometimes. He's the person who told me
Glad it worked though.
the auto-margins are the de-facto way to do horizontal centering, from what i've gathered. i think ie prefers the text-align:center, though.