HTML 테이블 생성
먼저, <colgroup> 태그를 사용하여 스타일을 적용하려는 HTML 테이블을 생성합니다. 다음 코드를 HTML 파일에 추가하십시오.
<!doctype html>
<html>
<head>
<title>Colored Table</title>
</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>
위 코드는 테두리가 1 이고 캡션이 "Colored Table"인 테이블을 생성합니다. <colgroup> 태그는 세 개의 <col> 태그를 포함하며, 각 태그는 세 개의 열에 서로 다른 색상을 적용합니다. <thead> 태그는 세 개의 열의 제목을 포함하는 세 개의 <th> 태그를 포함합니다. 그리고 <tbody> 태그는 각각 세 개의 열이 있는 두 개의 행을 포함합니다.