-3

I have two div tags:

<div id="parent">
    <div id="content">
          //content
    </div>
</div>

the content of the <div id="content"> is added dynamically so I don't know its width and I can't set width and margin to it.

How can I center align <div id="parent"> content?

PS: I don't want to use javascript to do this.

mmcglynn
  • 7,668
  • 16
  • 52
  • 76
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
  • 4
    Yeah, centering stuff with CSS – that’s totally a new question, has _never_ been asked before … – CBroe Nov 04 '13 at 12:50
  • Centering div with unknown width http://stackoverflow.com/questions/8228536/centering-div-with-unknown-width – 0xAli Nov 04 '13 at 12:56
  • possible duplicate of [How to center a div in a div - horizontally?](http://stackoverflow.com/questions/114543/how-to-center-a-div-in-a-div-horizontally) – They call me Trinity Nov 04 '13 at 13:00

2 Answers2

11

Try this:

#parent {
   text-align: center;
}

#content {
   display: inline-block;
}
Charles Ingalls
  • 4,521
  • 5
  • 25
  • 33
1

You can use text-align property.

#parent {
 text-align: center;
}
Praveen
  • 55,303
  • 33
  • 133
  • 164