HTML DOM tableLayout 属性

定义和用法

tableLayout 属性用来显示表格单元格、行、列的算法规则。

固定表格布局:

固定表格布局与自动表格布局相比,允许浏览器更快地对表格进行布局。

在固定表格布局中,水平布局仅取决于表格宽度、列宽度、表格边框宽度、单元格间距,而与单元格的内容无关。

通过使用固定表格布局,用户代理在接收到第一行后就可以显示表格。

自动表格布局:

在自动表格布局中,列的宽度是由列单元格中没有折行的最宽的内容设定的。

此算法有时会较慢,这是由于它需要在确定最终的布局之前访问表格中所有的内容。

语法:

Object.style.tableLayout=automatic|fixed

可能的值

描述
automatic 默认。列宽度由单元格内容设定。
fixed 列宽由表格宽度和列宽度设定。

实例

本例设置固定表格布局:

<html>
<head>
<script type="text/javascript">
function setFixedTableLayout()
{
document.getElementById('myTable').style.tableLayout="fixed";
}
</script>
</head>
<body>

<table id="myTable" border="1" width="100%">
<col width="20%"><col width="40%"><col width="40%">
<tr>
<td>1000000000000000000000000000</td>
<td>10000000</td>
<td>100</td>
</tr>
</table>

<input type="button" onclick="setFixedTableLayout()"
value="Set fixed table layout">

</body>
</html>