Module: M4-R5: Internet of Things (IoT)
Chapter: Ch1 Computer Intro
CSS Table properties allow you to style HTML tables, control spacing, borders, layout, captions, and text alignment.
Controls table and cell borders, and whether borders are collapsed.
<style>
table {
border: 2px solid #007bff;
border-collapse: collapse; /* or separate */
}
th, td {
border: 1px solid #28a745;
padding: 10px;
}
</style>
<table>
<tr><th>>Name</th><th>>Age</th></tr>
<tr><td>Alice</td><td>20</td></tr>
</table>
Defines space between cells (only with border-collapse: separate).
<style>
table {
border-collapse: separate;
border-spacing: 15px;
}
</style>
Positions the table caption at top or bottom.
<style>
caption {
caption-side: top;
font-weight: bold;
}
</style>
<table>
<caption>Student Info</caption>
<tr><th>>Name</th><th>Age</th></tr>
<tr><td>Alice</td><td>20</td></tr>
</table>
Controls display of empty cells.
<style>
td {
empty-cells: show; /* or hide */
}
</style>
Controls table column width algorithm.
<style>
table {
table-layout: fixed; /* or auto */
width: 100%;
}
th, td {
width: 50%;
}
</style>
Set table or cell width, height, and text alignment.
<style>
td {
width: 150px;
height: 50px;
text-align: center; /* left, right, center */
}
</style>
| Property | Description |
|---|---|
| border | Table border style |
| border-collapse | Collapse or separate borders |
| border-spacing | Space between cells |
| caption-side | Position of caption |
| empty-cells | Show/hide empty cells |
| table-layout | Column width layout (auto/fixed) |
| width / height | Table or cell size |
| text-align | Text alignment in cells |