How to place the "table" at the middle of the webpage?

107,506

Solution 1

The shortest and easiest answer is: you shouldn't vertically center things in webpages. HTML and CSS simply are not created with that in mind. They are text formatting languages, not user interface design languages.

That said, this is the best way I can think of. However, this will NOT WORK in Internet Explorer 7 and below!

<style>
  html, body {
    height: 100%;
  }
  #tableContainer-1 {
    height: 100%;
    width: 100%;
    display: table;
  }
  #tableContainer-2 {
    vertical-align: middle;
    display: table-cell;
    height: 100%;
  }
  #myTable {
    margin: 0 auto;
  }
</style>
<div id="tableContainer-1">
  <div id="tableContainer-2">
    <table id="myTable" border>
      <tr><td>Name</td><td>J W BUSH</td></tr>
      <tr><td>Proficiency</td><td>PHP</td></tr>
      <tr><td>Company</td><td>BLAH BLAH</td></tr>
    </table>
  </div>
</div>

Solution 2

Try this :

<style type="text/css">
        .myTableStyle
        {
           position:absolute;
           top:50%;
           left:50%; 

            /*Alternatively you could use: */
           /*
              position: fixed;
               bottom: 50%;
               right: 50%;
           */


        }
    </style>
Share:
107,506
OM The Eternity
Author by

OM The Eternity

M a PHP Programmer.. And an Experienced Tester, And a Vocalist...

Updated on April 07, 2020

Comments

  • OM The Eternity
    OM The Eternity about 4 years

    I have a very basic Table structure to be placed in middle/center of the web page. I Have a code below, I know its incomplete to make this happen, as I am bad in structuring the HTML part, please help me

    <div align="center" style="vertical-align:bottom">
    <div align="center" style="vertical-align:bottom">
    <table>
    <tr><td colspan="2"></td></tr>
    <tr><td>Name</td><td>J W BUSH</td></tr>
    <tr><td>Proficiency</td><td>PHP</td></tr>
    <tr><td>COmpany</td><td>BLAH BLAH</td></tr>
    </table>
    </div>
    </div>
    

    Also Please explain the concept behind the application of properties and CSS in achieving this time of structuring. so that I can use it in further learning....

    I am completely newbie and dumb in HTML-CSS use... So I request you all the techies and Geeks to bear with my silly questions of HTML-CSS structuring.. Please dont leave the comments which demoralize me to go ahead with learning like "Is it a Homework..." or "GO TO TUTION CLASSES"etc...