+ -
当前位置:首页 → 问答吧 → 不用!DOCTYPE的时候怎么居中表格

不用!DOCTYPE的时候怎么居中表格

时间:2011-03-02

来源:互联网

HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    -------------如果去掉这行居中代码就不起作用了
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>无标题页</title>
    <style>
        .bb
        {
            width: 200px;
            border: solid 1px #000;
            margin: 0 auto;         //不用!DOCTYPE的时候改行失效
            display: block;
        }
    </style>
</head>
<body>
    <table class="bb">
        <tr>
            <td>
                fdasfasdfasdfasdf
            </td>
        </tr>
    </table>
    <div class="bb">
        dfasdf</div>
</body>
</html>


请问怎么能够让table居中呢,只用css,不用table的align=center

作者: popo0027   发布时间: 2011-03-02

给body定义样式 body { text-align:center;}

作者: athrunzero   发布时间: 2011-03-02

<center></center>

作者: Ariels   发布时间: 2011-03-02

body { text-align:center;}的话会影响到其他的元素
<center></center>也不行,因为只能用css方法来改

现在用的办法是d:express(this.align="center");

不过也不太想用这个,毕竟ie才明白

作者: popo0027   发布时间: 2011-03-02

那你就加上<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
不懂干嘛要去掉

作者: athrunzero   发布时间: 2011-03-02