i know its a simple question, but how would i align a <table> tag to the center of the page, using css?
thanks
thanks
<table style="width:90%; margin:auto"> .... </table>
.automargin { margin:auto; position:absolute; }
<div class="automargin"></div>
<style type="text/css"> table {border: 1px dashed fuchsia/*for testing only*/;overflow:hidden/* to open the table if it is necessary*/; width:whatever its width is in pixels, percent, or em; margin: 0 auto;} </style>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> </head> <body> <table id="someTable" class="myTableStyle" border="1px"> <tr> <td>colum1 row1</td> <td>column2 row1</td> </tr> <tr> <td>colum1 row2</td> <td>column2 row2</td> </tr> </table> </body>
<style type="text/css"> .myTableStyle { width:200px; /* Now that the width has been set, we can use the margin style to center it horizontally. It will center horizontally by setting the margin-left and margin-right styles to 'auto' The following style sets the margin-left, margin-right, margin-top, and margin-bottom to 'auto'. Alternatively you could do: margin:0px auto; This will set the margin-top and margin-bottom to 0px and the margin-left and margin-right to auto. You can also specify each one: margin:5px auto 10px auto; This will set the margin-top to 5px, bottom to 10px, and left & right to auto. Or you can simply do: margin-left:auto; margin-right:auto; */ margin: auto; } </style>
<style type="text/css"> .myTableStyle { position:absolute; top:50%; left:50%; /*Alternatively you could use: */ /* position: fixed; bottom: 50%; right: 50%; */ } </style>
<style type="text/css"> .myTableStyle { position:fixed; height:50%; width:50%; top:25%; left:25%; /*Alternatively you could use: */ /* bottom:25%; right:25%; */ } </style>
<style type='text/css'> div{height:400px;width:200px;outline:1px solid;} button{position:relative;top:50%} </style> <div> <button type="submit">1</button> </div>
<style type='text/css'> html,body{height:100%} table{ top:50%; position:relative; height:100px; margin-top:-50px; outline:1px solid; } </style> <table> <tr><td>hello</td></tr> </table>
Comment