Cod*_*lue 64 html css html-table center
我使用以下代码.如何使用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>
Mic*_*son 91
html, body {
    width: 100%;
}
table {
    margin: 0 auto;
}
示例JSFiddle
垂直对齐块元素并不是最简单的事情.下面的一些方法.
Dar*_*jax 19
您可以尝试使用以下CSS:
table {
    margin: 0px auto;            
}?
Gop*_*005 10
1)在CSS中将水平对齐设置为auto
margin-left: auto;
 margin-right: auto;
2)获取垂直对齐到页面中心添加到css之后
html, body {
        width: 100%;
}
例如 :
<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>
小智 8
<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>