在HTML中,可以使用CSS样式来设置表格居中,以下是一个简单的示例:
(图片来源网络,侵删)
1、创建一个HTML文件,例如table_center.html
,并在其中添加以下内容:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF8">
<meta name="viewport" content="width=devicewidth, initialscale=1.0">
<title>表格居中示例</title>
<style>
/* 设置表格居中 */
.center {
display: flex;
justifycontent: center;
alignitems: center;
height: 100vh; /* 高度设置为视口高度 */
}
</style>
</head>
<body>
<div class="center">
<!创建一个表格 >
<table border="1">
<tr>
<th>标题1</th>
<th>标题2</th>
</tr>
<tr>
<td>内容1</td>
<td>内容2</td>
</tr>
<tr>
<td>内容3</td>
<td>内容4</td>
</tr>
</table>
</div>
</body>
</html>
在这个示例中,我们使用了一个名为.center
的CSS类来设置表格居中,我们将这个类应用到一个包含表格的<div>
元素上,通过设置display: flex
、justifycontent: center
和alignitems: center
,我们可以使表格在其父元素中水平和垂直居中,我们将表格的高度设置为视口高度(height: 100vh
),以确保表格在整个页面上居中。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)