What's the best way to center a DIV using CSS?
We Rock Your Web Forum » Markup Languages » CSS
CSS Center Div?
(2 posts)-
Posted 2 years ago #
-
Posted 2 years ago
-
The quickest way to center a DIV using CSS is the following:
body {
text-align: center;
}#centeredDIV {
margin: 0 auto;
}There's other methods, but we recommend the above one for simplicity. Another one that works fell is the negative left margin method:
#centeredDIV {
width:500px;
left:50%;
margin-left:-250px;
}Basically you want to give the DIV a negative left margin equal to half the width of the DIV.
Posted 2 years ago #