DEV Community

loading...

Discussion on: 1 line css to center object

Collapse
dsaw profile image
Devesh Sawant

That or our gold old margin (works in IE6) :)

div {
   width: 100%;
   margin: 0 auto;
}
Collapse
markohologram profile image
Marko A

Unfortunately, this doesn't center the element vertically, only horizontally. But if you just need to center the element horizontally, then just the margin trick will work just fine.

Btw, you don't need width: 100% in this code here, div is a block level element and has 100% width by default.