怎么用css 让整个table位置页面水平居中,

html-css026

怎么用css 让整个table位置页面水平居中,,第1张

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

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

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

3、最后,浏览器运行index.html页面,此时会发现通过用css让整个table在页面中水平居中成功。

1、普通居中。

align="center"

<table align="center">

  <tr>

   <td>商品名称</td>

   <td>商品价格</td>

   <td>商品描述</td>

   <td>购买</td>

  </tr>

 </table>

2、css样式居中。

margin:0 auto

<style type="text/css">

 table1{

  margin:0 auto/* 自动居中,不论王爷的大小 */

  border:1/* 边框粗度 */

  width:80%/* 宽度只占当前页面的80% */

 }

</style>