HTML DOM Style tableLayout 屬性
定義和用法
tableLayout 屬性設置或返回表格單元格、行、列的顯示算法規則。
語法
設置tableLayout 屬性:
Object.style.tableLayout="automatic|fixed|inherit"
返回tableLayout 屬性:
Object.style.tableLayout
值 | 描述 |
---|---|
auto | 默认。列宽度由单元格内容设定。
|
fixed | 列宽度由表格宽度和列宽度设定(不是由单元格内容设定)。
|
inherit | tableLayout 属性的值从父元素继承。 |
瀏覽器支持
所有主要瀏覽器都支持tableLayout 屬性。
注意: IE7及更早的版本不支持"inherit"值。IE8 只有規定了!DOCTYPE 才支持"inherit"。 IE9 支持"inherit"。
實例
實例
設置固定的表格佈局:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("myTable").style.tableLayout="fixed";
}
</script>
</head>
<body>
<table id="myTable" width="300" border="1">
<thead>
<th>表格表头</th>
<th>表格表头</th>
</thead>
<tbody>
<tr>
<td>这是一些文本。这是一些文本。</td>
<td>这是另一些文本</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">设置固定的表格布局</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("myTable").style.tableLayout="fixed";
}
</script>
</head>
<body>
<table id="myTable" width="300" border="1">
<thead>
<th>表格表头</th>
<th>表格表头</th>
</thead>
<tbody>
<tr>
<td>这是一些文本。这是一些文本。</td>
<td>这是另一些文本</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">设置固定的表格布局</button>
</body>
</html>
嘗試一下»
Style對象