Style tableLayout 属性

Style 对象参考手册 Style 对象

定义和用法

tableLayout 属性设置或返回表格单元格、行、列的显示算法规则。

语法

设置 tableLayout 属性:

Object.style.tableLayout="automatic|fixed|inherit"

返回 tableLayout 属性:

Object.style.tableLayout

描述
auto 默认。列宽度由单元格内容设定。
  • 这种布局有时是缓慢的,因为它需要在表格完全显示之前访问所有内容。
fixed 列宽度由表格宽度和列宽度设定(不是由单元格内容设定)。
  • fixed 布局的速度比 auto 布局快,因为用户代理在接收到第一行后就可以显示表格。
inherit tableLayout 属性的值从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 tableLayout 属性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


实例

实例

设置固定的表格布局:

<html>
<head>
<script>
function displayResult()
{
document.getElementById("myTable").style.tableLayout="fixed";
}
</script>
</head>
<body>

<table id="myTable" width="300" border="1">
<thead>
<th>Table header</th>
<th>Table header</th>
</thead>
<tbody>
<tr>
<td>This is some text. This is some text.</td>
<td>This is another text.</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">Set fixed table layout</button>

</body>
</html>

尝试一下 »


Style 对象参考手册 Style 对象