CSS TABLE Tutorial
CSS TABLE Tutorial
เรา set อะไรให้กับ div ได้ เราก็ set ให้กับ table ได้หมด
<table>
<tr>
<td class="box">Cell
1</td>
<td class="box">Cell
2</td>
</tr>
<tr>
<td class="box">Cell
3</td>
<td class="box">Cell
4</td>
</tr>
</table>
<style>
.box {
color: blue;
/* Text color */
font-size: 16px;
/* Font size */
background-color: lightgray; /* Background color */
padding: 10px;
/* Padding inside the cell */
border: 1px solid black; /* Border around the cell */
text-align: center;
/* Center text alignment */
}
</style>
Table Properties
: Sets the border around the table.
border
table {
border: 1px solid black;
}
.
1
2. : Merges table borders into a singleborder.
border-collapse
○ Values: ,
collapse .
separate
table {
border-collapse: collapse;
}
3.
table {
width: 100%; /* Full width of the parent container */
}
4.
table {
height: 200px;
}
.
5
6. : Specifies the position of the tablecaption (if any).
caption-side
○ Values: ,
top ,
bottom ,
left .
right
table {
caption-side: top;
}
7.
tr {
background-color: #f2f2f2; /* Light gray */
}
1.
tr {
height: 50px;
}
2.
td, th {
padding: 10px; /* Space inside the cells */
}
1.
td, th {
border: 1px solid black;
}
td, th {
text-align: center; /* Center text */
}
4.
td, th {
color: blue; /* Text color */
}
5.
td, th {
font-size: 16px;
}
6.
th {
font-weight: bold; /* Bold header cells */
}
7.
td {
background-color: #e0e0e0; /* Light gray */
}
Example of Table Styling
<style>
table {
border-collapse: collapse;
width: 100%;
border: 1px solid black;
}
th, td {
padding: 10px;
border: 1px solid black;
text-align: center;
vertical-align: middle;
}
th {
background-color: #f2f2f2; /* Light gray for header */
font-weight: bold;
}
td {
background-color: #e0e0e0; /* Light gray for data cells */
}
</style>