HTML DOM Style tableLayout 属性

htmldomweb developmentfront end technology更新于 2024/5/23 18:20:17

HTML DOM Style tableLayout 属性返回并修改 HTML 文档中表格单元格、行和列的布局方式。

语法

以下是语法 −

1. 返回 tableLayout

object.tableLayout

2. 修改 tableLayout

object.tableLayout = “value”

此处值可以为 -

值说明
initial将此属性值设置为默认值。
inherit从其父元素继承此属性值。
fixed根据列和表格的宽度设置列宽。
auto根据表格中最宽的不可拆分内容的宽度设置列宽。

让我们看一个 HTML DOM Style tableLayout 属性的示例 −

示例

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      background: lightblue;
      height: 100vh;
      text-align: center;
   }
   table {
      margin: 2rem auto;
      width: 400px;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
<body>
<h1>DOM Style tableLayout Property Demo</h1>
<table border="2">
<caption>Student Entry</caption>
<tr>
<th>Name</th>
<th>Roll No.</th>
</tr>
<tr>
<td>John</td>
<td>031717</td>
</tr>
<tr>
<td>Elon</td>
<td>041717</td>
</tr>
</table>
<button onclick="show()" class="btn">Set tableLayout</button>
<script>
   function show() {
      document.querySelector('table').style.tableLayout = "fixed";
   }  
</script>
</body>
</html>

输出

点击“设置 tableLayout” 按钮,将 tableLayout 设置为固定 值 −


相关文章


有用资源