The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Help centering a div Re: Help centering a div


Figured it out. My top answer wasn’t quite right when I tried it. But, then I remembered an article I read about how to center unordered lists in a nav when you don’t know their width. This is pretty much the same thing.

First I wrap my main div in another div, which I fix to the top. I then put left:50% on it. Then on my main div I make position relative and put left:-50% on it. And that centers it no matter what the width is.