如何使用 CSS 将表格放在页面中央? [英] How to put table in the center of the page using CSS?
本文介绍了如何使用 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.
这篇关于如何使用 CSS 将表格放在页面中央?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文