Centering a div is Not Terribly Obvious

WebDevel.jpg

I was once again trying to center a div on a page and I ran into the same problem I'd had before - centering that div. So when I looked this guy up this time, I decided to make a note of the solution so I could always find the solution no matter what.

This is that note.

The solution should be:

  div {
    align: center;
  }

but for some reason, the internet powers that be decided that this was not nearly as obvious and clear as the real solution:

  div {
    margin-left: auto;
    margin-right: auto;
  }

Don't get me wrong, the margin-left and margin-right attributes are nice, and they have a lot of use in a lot of cases, but to use them to center a div over the more obvious align attribute is a little... well... let's just call it non-obvious.

So there we have it. I'll probably never forget this again. Figures.