<header>
<h2 class="title">element.style.tableLayout</h2>
<p class="description">Встановлює або повертає макет таблиці для елемента.</p>
</header>
<main>
<div class="result">
<button id="toggleLayout">Перемкнути макет таблиці</button>
<table id="myTable" border="1">
<tr>
<th>Назва</th>
<th>Вік</th>
<th>Місто</th>
</tr>
<tr>
<td>Олексій</td>
<td>28</td>
<td>Київ</td>
</tr>
<tr>
<td>Марія</td>
<td>22</td>
<td>Львів</td>
</tr>
<tr>
<td>Іван</td>
<td>35</td>
<td>Одеса</td>
</tr>
</table>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
#myTable {
width: 100%;
border-collapse: collapse;
}
#myTable th, #myTable td {
padding: 10px;
text-align: left;
}
button {
margin-bottom: 20px;
padding: 10px 20px;
cursor: pointer;
}
document.getElementById("toggleLayout").addEventListener("click", function() {
let table = document.getElementById("myTable");
if (table.style.tableLayout === "auto" || table.style.tableLayout === "") {
table.style.tableLayout = "fixed";
this.textContent = "Перемкнути на auto";
} else {
table.style.tableLayout = "auto";
this.textContent = "Перемкнути на fixed";
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.