คุณสมบัติ HTML DOM Style tableLayout ส่งคืนและแก้ไขวิธีการวางเซลล์ แถว และคอลัมน์ของตารางในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
1. การส่งคืน tableLayout
object.tableLayout
2. การปรับเปลี่ยน tableLayout
object.tableLayout = “value”
ค่านี้สามารถเป็น −
| ค่า | คำอธิบาย |
|---|---|
| เริ่มต้น | ตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | รับค่าคุณสมบัตินี้จากองค์ประกอบหลัก |
| แก้ไขแล้ว | กำหนดความกว้างของคอลัมน์ตามความกว้างของคอลัมน์และตาราง |
| อัตโนมัติ | กำหนดความกว้างของคอลัมน์ตามความกว้างของเนื้อหาที่ไม่แตกหักที่กว้างที่สุดในตาราง |
ให้เรามาดูตัวอย่าง HTML DOM Style tableLayout Property -
ตัวอย่าง
<!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 ด้วย แก้ไข ค่า -
