Use this, like said earlier.
Code:#div { margin: auto; }

Use this, like said earlier.
Code:#div { margin: auto; }
Previously a Habbo fanatic, web designer/developer, fansite owner, & trusted member of the community.
Because it doesn't work, try it yourself it only works for horizontal.
even with a fixed containerCode:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> #middle { width: 200px; margin: auto; background-color: #333; } </style> </head> <body> <div id="container"> <div id="middle"> Expands yay :)<br /> <br /> <br /> <br /> and yet not centered vertically :( </div> </div> </body> </html>
thus proving it does not WORK! for vertical aligning.Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> #container { width: 600px; height: 600px; background-color: #999; } #middle { width: 200px; margin: auto; background-color: #333; } </style> </head> <body> <div id="container"> <div id="middle"> Expands yay :)<br /> <br /> <br /> <br /> and yet not centered vertically :( </div> </div> </body> </html>
Last edited by Iszak; 25-10-2008 at 09:30 PM.
That had already been said twice, so pointless posts.
You didn't even read the topic.
"Best way of Vertical centering a div?"
That worked the bestJxhn is right to an extent in using vertical align, but for it to work you must set the parent/containing div to be display: table-cell; here is an example.
Now if you want something centered vertically in the body now that's a different story.Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> #container { width: 500px; height: 500px; display: table-cell; vertical-align: middle; background-color: #333; } #middle { width: 500px; background-color: #999; } </style> </head> <body> <div id="container"> <div id="middle"> Expands yay :)<br /> <br /> <br /> <br /> and yet still centered :P: </div> </div> </body> </html>
I might also add on Jxhn first post about the position: absolute; left: 50%; margin-left: -(width/2)px of course you don't do it like that you do the calculations this has one slight problem - you've got to set the parent to position: relative; otherwise it'll fail.
I had to change the container to display:table and the middle to display:table-cell because there were 3 containers next to each other acting like cells
Anyways, +rep to everyone who helped![]()
Yes I did.
is how v-align I thought was used and I thought that he just wanted it centered, excuse my mistake.Code:v-align: top; v-align: bottom;
-REP (Need to spread, won't forget..)
You only said center? He said vertical alignment. You can't -rep me because you misread his post. I don't even understand the second sentence, could you rephrase it please?
Want to hide these adverts? Register an account for free!