Wednesday, May 25, 2005

How To Center Vertically and Horizontally With CSS

For the CSS method, this depends on whether you are facing quirks mode or standards mode.

The following centers a table.

table {margin: auto;}

If you are facing quirks mode in IE, then you must apply text-align: center; on the containing block.

div {
text-align: center; /* For IE Quirks and older IE's */
border: 1px solid black;
}

table {
margin: auto; /* For all other browsers */
border: 1px solid black;
}

<div>
<table>
<tr>
<td>test</td>
</tr>
</table>
</div>

0 Comments:

Post a Comment

<< Home