JavaScript에서 테이블을 올바르게 레이아웃하려면 tableLayout을 사용하세요. 재산. 레이아웃을 설정하려면 속성을 fixed로 설정하세요.
예시
다음 코드를 실행하여 JavaScript로 테이블 셀, 행 및 열을 레이아웃하는 방법을 설정할 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<style>
table, td {
border: 2px solid blue;
}
#myID {
width: 100%;
}
</style>
</head>
<body>
<button onclick = "display()">Set Layout Property</button>
<table id = "myID">
<tr>
<td>This is a text for demo</td>
<td>This is another text</td>
</tr>
<tr>
<td>One</td>
<td>1</td>
</tr>
<tr>
<td>Two</td>
<td>2</td>
</tr>
<tr>
<td>Three</td>
<td>3</td>
</tr>
</table>
<script>
function display() {
document.getElementById("myID").style.tableLayout = "fixed";
}
</script>
</body>
</html>