How to vertical center a table in a <div> container

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    How to vertical center a table in a <div> container

    I don't seem to be able to do a vertical center on the table contained in this <div> </div> tag. What needs to be done?


    Code:
    <div id="container" style="height:90%; width:95%; white-space:nowrap; border:5px solid red;margin: auto;">
    	<table style="margin: auto; vertical-align:center; border:2px solid blue;">
    		<tbody>
    			<tr>
    				<td align="right" >Initials:</td>
    				<td><input type="text" name=""></td>
    			</tr><tr>
    				<td>Engineer's Name:</td>
    			</tr><tr>
    				<td align="right" >First Name:</td>
    				<td><input type="text" /></td>
    			</tr><tr>
    				<td align="right" >Last Name:</td>
    				<td><input type="text"/></td>
    			</tr>
    		</tbody>
    	</table>
    </div>
  • Rangan
    New Member
    • Dec 2012
    • 8

    #2
    Instead of setting margin:auto margin-left:10px and margin-top:10;

    increasing left and top position table will center aligned by vertically.

    check this will help you too..

    Comment

    • martin631775
      Banned
      New Member
      • Dec 2012
      • 13

      #3
      Here is the correction code..
      for more help <link removed>
      Code:
        <div id="container" style="display:table-cell;vertical-align:middle;height:1000px; width:95%; white-space:nowrap; border:5px solid red;margin: auto;">
            <table style="margin:0 auto; border:2px solid blue;">
                  <tbody>
                      <tr>
                          <td align="right" >Initials:</td>
                          <td><input type="text" name=""></td>
                      </tr><tr>
                          <td>Engineer's Name:</td>
                      </tr><tr>
                          <td align="right" >First Name:</td>
                          <td><input type="text" /></td>
                      </tr><tr>
                          <td align="right" >Last Name:</td>
                          <td><input type="text"/></td>
                      </tr>
                  </tbody>
              </table>
          </div>
      Last edited by Rabbit; Dec 31 '12, 08:50 AM. Reason: Link to outside site removed.

      Comment

      Working...