Saturday, October 3, 2015

Centering An Element on a Web Page

1. Give the element a width
2. Set its margins to auto

Like this:

div {
  width: 200px;
  margins: auto;
}

If you don't give it a width, and it doesn't have a small enough width by default, setting the margins to auto won't have an effect.

No comments:

Post a Comment