我正在使用以下代码。如何使用 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>
原文由 CodeBlue 发布,翻译遵循 CC BY-SA 4.0 许可协议
2022 年编辑:请使用 Flexbox
使用 Flexbox,说明在这里: https ://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container
2021 年答案保留在下方。
示例 JSFiddle
垂直对齐块元素并不是最简单的事情。下面的一些方法。