HTML <thead> 태그


예시

<thead>, <tbody> 및 <tfoot> 요소가 있는 HTML 테이블:

<table>
  <thead>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td>$180</td>
    </tr>
  </tfoot>
</table>

아래에서 더 많은 "직접 사용해 보기" 예를 살펴보세요.


정의 및 사용

<thead>태그는 HTML 테이블의 헤더 내용을 그룹화하는 데 사용됩니다 .

요소는 표의 각 부분(머리글, 본문, 바닥글)을 지정하기 위해 <tbody><tfoot><thead> 요소 와 함께 사용됩니다 .

브라우저는 이러한 요소를 사용하여 머리글 및 바닥글과 별도로 테이블 본문을 스크롤할 수 있습니다. 또한 여러 페이지에 걸쳐 있는 큰 표를 인쇄할 때 이러한 요소를 사용하면 표 머리글과 바닥글을 각 페이지의 위쪽과 아래쪽에 인쇄할 수 있습니다.

참고: 요소 에는 내부 <thead>에 하나 이상의 <tr> 태그가 있어야 합니다.

<thead>태그는 다음 컨텍스트에서 사용해야 합니다. <table> 요소의 자식으로, < caption > 및 <colgroup> 요소 뒤 , < tbody > , < tfoot><tr> 요소 앞.

팁: , <thead><tbody> 및 <tfoot> 요소는 기본적으로 테이블 레이아웃에 영향을 주지 않습니다. 그러나 CSS를 사용하여 이러한 요소의 스타일을 지정할 수 있습니다(아래 예 참조)!


브라우저 지원

Element
<thead> Yes Yes Yes Yes Yes

전역 속성

<thead>태그는 HTML의 전역 속성도 지원 합니다 .


이벤트 속성

<thead>태그는 HTML의 이벤트 속성 도 지원합니다 .



더 많은 예

예시

CSS로 <thead>, <tbody> 및 <tfoot> 스타일 지정:

<html>
<head>
<style>
thead {color: green;}
tbody {color: blue;}
tfoot {color: red;}

table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<table>
  <thead>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td>$180</td>
    </tr>
  </tfoot>
</table>

예시

<thead> 내부의 콘텐츠를 정렬하는 방법(CSS 사용):

<table style="width:100%">
  <thead style="text-align:left">
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
</table>

예시

<thead> 내부 콘텐츠를 세로로 정렬하는 방법(CSS 사용):

<table style="width:50%;">
  <thead style="vertical-align:bottom">
    <tr style="height:100px">
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
   <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$80</td>
    </tr>
  </tbody>
</table>

기본 CSS 설정

대부분의 브라우저는 <thead>다음 기본값으로 요소를 표시합니다.

thead {
  display: table-header-group;
  vertical-align: middle;
  border-color: inherit;
}