より良いスタイリングのためのCSSの記述
このステップでは、CSSを使用して上記で作成したテーブルにスタイルを適用します。
HTMLファイルに以下のCSSコードを追加します。
<!doctype html>
<html>
<head>
<title>Colored Table</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #4169e1;
color: white;
}
</style>
</head>
<body>
<table border="1">
<caption>
Colored Table
</caption>
<colgroup>
<col style="background-color: gray;" />
<col style="background-color: lightblue;" />
<col style="background-color: lightgreen;" />
</colgroup>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
<td>Row 1, Column 3</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
<td>Row 2, Column 3</td>
</tr>
</tbody>
</table>
</body>
</html>
index.html
ファイルの完成したコードを確認します。各列に異なる色がある3列のテーブルが表示されるはずです。