css怎么让表格居中

html-css014

css怎么让表格居中,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码:body {text-align: center} table {margin: auto}。

3、浏览器运行index.html页面,此时成功用css让表格居中了。

可以让Input向左浮动,当然之后不要忘记清除浮动:

<style>

    div {width:600px height:40px text-align:center border:1px solid #000}

    div input {float:left}

    div input:after {content:"" clear:both}

</style>

<div><input type=text value="test"/>这是标题文字</div>

或者用绝对定位:

<style>

    div {position:relative width:600px height:40px text-align:center border:1px solid #000}

    div input {position:absolute left:0 top:0}

</style>

<div><input type=text value="test"/>这是标题文字</div>

从效果来看是第2种好(第1种的input会占用文字的宽度),而且兼容性也是第2种好(不需要css3)