Style tableLayoutProperty

Style 对象参考手册Style Object

Definition and Usage

The tableLayout property sets or returns the display algorithm rules for table cells, rows, and columns.

Syntax

Set the tableLayout property:

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

Return the tableLayout property:

Object.style.tableLayout

Value Description
auto Default. Column width is set by cell content.
  • This layout is sometimes slow because it needs to access all content before the table is fully displayed.
fixed Column width is set by the table width and column width (not by cell content).
  • The fixed layout is faster than the auto layout because the user agent can display the table after receiving the first row.
inherit The value of the tableLayout property is inherited from the parent element.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the tableLayout property.

Note:IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".


Example

Example

Set a fixed table layout:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<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 some other text</td>
    </tr>
    </tbody>
</table>
<br>
<button type="button" onclick="displayResult()">Set fixed table layout</button>

</body>
</html>

Try it Yourself »


Style 对象参考手册Style Object Other Extensions