如何将表放在页面的中心使用CSS? [英] How to put table in the center of the page using CSS?

查看:182
本文介绍了如何将表放在页面的中心使用CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码。如何使用CSS将此表放在页面中心?

I am using the following code. How to put 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>


推荐答案

html, body {
    width: 100%;
}
table {
    margin: 0 auto;
}

示例 JSFiddle

垂直对齐块元素不是最微不足道的事情。以下的一些方法。

Vertically aligning block elements is not the most trivial thing to do. Some methods below.

  • Understanding vertical-align, or "How (Not) To Vertically Center Content"
  • Vertical Centering in CSS

这篇关于如何将表放在页面的中心使用CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆