HTML <colgroup> 태그


예시

<colgroup> 및 <col> 태그를 사용하여 세 열의 배경색을 설정합니다.

<table>
  <colgroup>
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
</table>

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


정의 및 사용

태그 는 <colgroup>형식화를 위해 테이블에 있는 하나 이상의 열 그룹을 지정합니다.

<colgroup>태그는 각 행에 대해 각 셀의 스타일을 반복하는 대신 전체 열에 스타일을 적용하는 데 유용합니다 .

참고: 태그 <colgroup>는 <caption> 요소 뒤와 <thead>, <tbody>, <tfoot> 및 <tr> 요소 앞에 있는 <table> 요소의 자식이어야 합니다.

팁: 내에서 열에 다른 속성을 정의하려면 태그 내에서 <col><colgroup> 태그를 사용하십시오 .<colgroup>


브라우저 지원

Element
<colgroup> Yes Yes Yes Yes Yes

속성

Attribute Value Description
span number Specifies the number of columns a column group should span

전역 속성

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


이벤트 속성

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



더 많은 예

예시

표 열의 텍스트 정렬(CSS 사용):

<table style="width:100%">
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td style="text-align:right">$53</td>
  </tr>
  <tr>
    <td>2489604</td>
    <td>My first CSS</td>
    <td style="text-align:right">$47</td>
  </tr>
</table>

예시

테이블 열의 텍스트 수직 정렬(CSS 사용):

<table style="height:200px">
  <tr>
    <th>Month</th>
    <th style="vertical-align:bottom">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td style="vertical-align:bottom">$100</td>
  </tr>
</table>

예시

테이블 열의 너비 지정(CSS 사용):

<table>
  <tr>
    <th style="width:200px">Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

관련 페이지

HTML DOM 참조: ColumnGroup 개체


기본 CSS 설정

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

예시

colgroup {
  display: table-column-group;
}