To manage the distance between the border and the content within a table, apply the padding property to <td> and <th> elements.
First Name | Last Name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Example
th, td { padding: 15px; text-align: left; } |
First Name | Last Name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Include the border-bottom property in <th> and <td> elements to create horizontal dividers.
Example
th, td { border-bottom: 1px solid #ddd; } |
Apply the :hover selector to <tr> elements to highlight table rows when hovered over with the mouse.
First Name | Last Name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Example
tr:hover {background-color: coral;} |
First Name |
Last Name |
Savings |
Peter |
Griffin |
$100 |
Lois |
Griffin |
$150 |
Joe |
Swanson |
$300 |
To create zebra-striped tables, utilize the nth-child() selector to target specific table rows and apply a background-color to every even (or odd) row.
Example
tr:nth-child(even) {background-color: #f2f2f2;} |
The following example defines the background color and text color for <th> elements.
First Name |
Last Name |
Savings |
Peter |
Griffin |
$100 |
Lois |
Griffin |
$150 |
Joe |
Swanson |
$300 |
Example
th { background-color: #04AA6D; color: white; } |