Tyler Crompton
Tyler Crompton

Reputation: 12672

Why is my div element not centering?

I feel like I am missing something easy or stupid. This is the only element on my page that I can't seem to center. I cannot seem to centerul#footer.

http://jsfiddle.net/w67rt/

Upvotes: 0

Views: 12089

Answers (3)

Mathias Bynens
Mathias Bynens

Reputation: 149804

To center the footer contents horizontally, just add the following CSS:

#footer {
  text-align: center;
}

Demo: http://jsfiddle.net/mathias/GZ6xh/

If you’re looking to center the entire element, just give it a width and then use margin: 0 auto:

#footer {
  width: 400px;
  margin: 0 auto;
}

Upvotes: 2

Jan Daniel
Jan Daniel

Reputation: 131

I find two solutions:

both here, one is commented: http://jsfiddle.net/AzNqm/

  1. define width of ul, and center block with margin:auto
  2. center inner li elements

Effect will be the same.

Upvotes: 0

Geeklab
Geeklab

Reputation: 199

The width of ul#footer is undefined, so it uses the default width of "100%". I tried using width:261px, and then it does center.

Upvotes: 1

Related Questions