DEV Community

Discussion on: How to center things in CSS 💘

Collapse
 
danielpdev profile image
danielpdev • Edited

You could also use the old style:

#content {
margin: 0 auto;
}

but this works only on block elements, so just add display: block; for inline elements.

Thanks for sharing!

Collapse
 
alvaromontoro profile image
Alvaro Montoro

That would only center horizontally though.

Collapse
 
danielpdev profile image
danielpdev

Yes, that's right.
Although, to align both horizontally and vertically you can also use margin in combination with position.

here is an example