How to place the table in the center of the page using CSS?

I am using the following code. How to place this table in the center of the page using CSS?

<html> <head> <link rel="stylesheet" type="text/css" href="styles.css" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>The Main Page</title> </head> <body> <table> <tr> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> </tr> </table> </body> </html> 
+46
html css html-table center
Feb 22 2018-12-22T00:
source share
6 answers
 html, body { width: 100%; } table { margin: 0 auto; } 

JSFiddle example

Vertical alignment of block elements is not the most trivial thing. Below are some methods.

+60
Feb 22 '12 at 20:59
source share

You can try using the following CSS:

 table { margin: 0px auto; }​ 
+14
Feb 22 '12 at 20:59
source share
 <html> <head> <meta charset="ISO-8859-1"> <style type="text/css"> table.center { margin-left: auto; margin-right: auto; } </style> <title>Table with css</title> </head> <body> <table class="center"> <tr> <th>SNO</th> <th>Address</th> </tr> <tr> <td>1</td> <td>yazali</td> </tr> </table> </body> </html> 
+7
Jan 21 '14 at 5:23
source share

1) Setting horizontal alignment to auto in CSS

margin-left: auto; margin-right: auto;

2) Get vertical alignment to the center of the page add the following to css

html, body { width: 100%; }

For example:

 <html> <head> <meta charset="ISO-8859-1"> <style type="text/css"> table.center { margin-left: auto; margin-right: auto; } html, body { width: 100%; } </style> <title>Table with css</title> </head> <body> <table class="center"> <tr> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> <td><button class="lightSquare"></button></td> <td><button class="darkSquare"></button></td> </tr> </table> </body> </html> 
+4
Apr 15 '15 at 6:19 06:19
source share

If you ask the table to fill the center, like something in a common center, you can apply the following code.

 margin: 0px auto; margin-top: 13%; 

this code in css will allow you to place your table as floating. Tell me if this helps you.

0
Mar 16 '15 at 9:30
source share

just put it in a div, then run the div command whit css:

 <div class="your_position"> <table> </table> </div> 
0
Apr 07 '15 at 11:48
source share



All Articles