margin: auto;

The CSS margin property gets things centered, old reliable. YOU NEED A WIDTH PROPERTY, THOUGH, OR IT WON’T WORK.

<style>

.centadis {margin: 0 auto; width: 75%;}

</style>

Use this class on an HTML element like a <div> to center it on the page. margin: 0 auto will center an element with a top and bottom margin of 0px. The auto replaces the margin left/right value to allow the CSS to “auto center” the element.

Give it a whirl, you probably already know about it, and use it, but just use it. All you can do is just use it! Ed Bassmaster.

Patrick Farrell

Director of Strategy/Operations, Janitor, Graphic Designer & Contributing Writer - The Bare Magazine

Next
Next

css tip #1 - the border shorthand property