How to display two div element in one line and align the whole in center?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tess1243
    New Member
    • Jun 2010
    • 20

    How to display two div element in one line and align the whole in center?

    How to display two div element in one line and align the whole in center?

    I know that we can display two div elements in one line by giving float:left;.

    But For Example:
    Code:
    <div class="MainDiv" id="div1">
      <div class="InnerDiv1" id="div2">
        <span>Hello,</span>
      </div>
      <div class="InnerDiv2" id="div3">
        <span>How are u doing?</span>
      </div>
    </div>
    I want the output to be

    "Hello, How are u doing?" that to be aligned centered

    If we give float:left; we get the text in one line but aligned to left.

    Is there any other way to get the desired output?
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    We don't do things this way but to get what you want:
    Code:
    <style>
    #div1{ width:200px; margin:0 auto}
    #div2, #div3 {display:inline}
    </style>
    <div class="MainDiv" id="div1">
      <div class="InnerDiv1" id="div2">
        <span>Hello,</span>
      </div>
      <div class="InnerDiv2" id="div3">
        <span>How are u doing?</span>
      </div>
    </div>

    Comment

    Working...