CSS Tables
HTML 테이블의 모양은 CSS로 크게 개선 될 수 있다:
Company | Contact | Country |
---|---|---|
Alfreds Futterkiste | Maria Anders | Germany |
Berglunds snabbköp | Christina Berglund | Sweden |
Centro comercial Moctezuma | Francisco Chang | Mexico |
Ernst Handel | Roland Mendel | Austria |
Island Trading | Helen Bennett | UK |
Königlich Essen | Philip Cramer | Germany |
Laughing Bacchus Winecellars | Yoshi Tannamuri | Canada |
Magazzini Alimentari Riuniti | Giovanni Rovelli | Italy |
North/South | Simon Crowther | UK |
Paris spécialités | Marie Bertrand | France |
The Big Cheese | Liz Nixon | USA |
Vaffeljernet | Palle Ibsen | Denmark |
Table Borders
CSS에서 표 테두리를 지정하려면 border 속성을 사용합니다.
아래의 예는 table, th 및 td 요소에 검은 색 테두리를 지정합니다:
Firstname | Lastname |
---|---|
Peter | Griffin |
Lois | Griffin |
위 예의 테이블에는 이중 테두리가 있습니다. 이는 table과 th 및 td 요소에 모두 별도의 경계가 있기 때문입니다.
테이블을 하나의 테두리로 표시하려면 border-collapse 속성을 사용한다.
Collapse Borders
border-collapse 속성은 표 테두리를 하나의 테두리로 축소 또는 분리 여부를 설정합니다 :
Firstname | Lastname |
---|---|
Peter | Griffin |
Lois | Griffin |
Example
table
{
border-collapse: collapse;
}
table, th, td {
border:
1px solid black;
}
Try
it yourself » Table Width and Height
테이블의 폭과 높이가 width 와 height 속성에 의해 정의된다.
아래의 예는 테이블의 폭을 100% 로, th 요소의 높이를 50px 로 정의 한다:
Firstname | Lastname | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Table Text Alignment
테이블의 텍스트는 text-align 과 vertical-align 속성으로 정렬됩니다.
text-align 속성은 left, right, 또는 center 같이 수평 정렬을 설정합니다:
vertical-align 속성은 top, bottom, 또는 middle 과 같은 수직 맞춤을 설정합니다:
Table Padding
테이블의 테두리와 내용 사이의 간격을 제어하려면, td 와 th 요소에 padding 속성을 사용합니다:
Horizontal Dividers
First Name | Last Name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Add the border-bottom
property to <th> and <td> for horizontal dividers:
Hoverable Table
<tr> 의 :hover
선택기를 사용하여 마우스로 테이블 행을 강조 표시하십시오:
First Name | Last Name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Striped Tables
First Name | Last Name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
얼룩말 줄무늬 테이블의 경우 nth-child()
선택기를 사용하고 모든 짝수 (또는 홀수) 테이블 행에 background-color
을 추가하십시오.:
Table Color
아래 예는 테두리의 색상, 텍스트 및 th 요소의 배경색을 지정:

More Examples
Make
a fancy table
This example demonstrates how to create a fancy table.
Set
the position of the table caption
This example demonstrates how to position the table caption.
Test Yourself with Exercises!
Exercise 1 » Exercise 2 » Exercise 3 » Exercise 4 » Exercise 5 » Exercise 6 »