我是个初学者,之前居中我都使用的center标签
由于center标签在html5中已经不被支持,我希望使用CSS来替换它,但是在实际使用中遇到了困难
使用center将body内的全部内容居中的代码如下:
<body>
<center>
<table width="850" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">{include file='top.tpl'}</td>
</tr>
<tr>
<td width="216" align="left" valign="top">
{include file='login.tpl'}
{include file='public.tpl'}
{include file='links.tpl'}
</td>
<td width="634" height="700" align="center" valign="top">
{include file='search.tpl'}
{include file=$admin_p_html}
</td>
</tr>
</table>
<table width="850" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>{include file='buttom.tpl'}</td>
</tr>
</table>
</center>
</body>
正常居中(报错请无视,代码还没敲完):
百度后我看到可以使用text-align:center
但是不论是在body中加入style="text-align:center"、style="text-align:center;margin:0 auto;"
还是定义一个div把body中的内容全部框进去再style="text-align:center"均不奏效
<body style="text-align: center">
<table width="850" border="0" cellspacing="0" cellpadding="0">
<!--略-->
</table>
<table width="850" border="0" cellspacing="0" cellpadding="0">
<!--略-->
</table>
</body>
<body style="text-align: center">
<div style="text-align: center">
<table width="850" border="0" cellspacing="0" cellpadding="0">
<!--略-->
</table>
<table width="850" border="0" cellspacing="0" cellpadding="0">
<!--略-->
</table>
</div>
</body>
结果均为(居中失败):
这种情况应该怎么写才能正确居中呢?