0

I have a box that I made in CSS and I want it to be aligned to the center. Unfortunately I have looked all over and cannot find an answer that works.
HTML:

<div id="top_bar">
        <div class="inner">

        </div>
</div>

CSS:

#top_bar {
vertical-align:text-top;
width: 90%;
/*padding: 10px;*/
border: 3px solid gray;
/*margin: auto;
margin-left: auto;
margin-right: auto;*/
position: fixed;
bottom: 0px;
}

#top_bar .inner {
  padding:10px;
}

body { margin-left:0px; }
Marcus S
  • 435
  • 4
  • 11
  • 15
  • That doesn't work. It just makes my bar not be stuck at the bottom(I am moving it to the top after). – Marcus S Nov 04 '11 at 14:31

4 Answers4

2

remove position:fixed, see this question for more info

Community
  • 1
  • 1
derek
  • 4,826
  • 1
  • 23
  • 26
1
#top_bar{
  margin:0 auto;
  /* Others .... */
}
Riz
  • 9,703
  • 8
  • 38
  • 54
0

Maybe try putting margin: auto on the inner div

rogerlsmith
  • 6,670
  • 2
  • 20
  • 25
0

Here is a working sample.

If a parent element like #wrapper in this case has text-align:center and the #content container inside has margin: 0 auto;, it'll center. You can play with this jsFiddle to get a feel for what different rules will do, and apply what you learn to your code above.

In your code above, position: fixed is forcing the container to a position. It'll need to be removed for centering to work as I've shown in my sample.

Steve Adams
  • 2,812
  • 22
  • 29