将表格对齐页面中心 [英] Align the table on the center of the page

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

问题描述

我只想将表格放在页面中间。任何帮助都很棒。

I just want to put the table in the middle of the page. Any help would be great.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Randy's first html web page !</title>
<style type="text/css">
body
{background-image:url('Koala.gif');} 
h1
{
text-align:center;
}
h2
{
text-align:center;
}
p
{
text-align:center;
font-size:200%;
color:#00fff0;
}
div
{
background-color:#efffff;
}
</style>
</head>
<h1> Hello Professor</h1>
<h2> By: Randy White</h2>
<P> I haven't done anything like this before.</P> 
<P>Seems to be ok</P>
<P><img src="Hydrangeas.jpg" width="150" height="100" alt="Hydrangeas.jpg"></P> 
<table border="1">
<tr>
<th>Month</th>
<th>Day</th>
<th>Year</th>
</tr>
<tr>
<td>December</td>
<td>1</td>
<td>2010</td>
</tr>
</table>
<a href="http://www.google.com">Visit Google!</a>
</body>
</html>


推荐答案

试试:

table {
    width: 50%;
    margin-left: auto;
    margin-right: auto;
}

或者:

or:

table {
    width: 200px;
    margin-left: auto;
    margin-right: auto;
}

顺便说一下,这个设置适用于所有表格。您可能希望在更具体的选择器上具有属性(如 table.someclass )。

BTW, this sets this for all tables. You might want to have the properties on a more specific selector (like table.someclass).

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

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