This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.
Smartphone icons created by Freepik - Flaticon
To control the space between the border and the content in a table, use the
property on <td> and <th> elements:First name | Last name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
th, td { padding: 15px; text-align: left; }
First name | Last name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
Add the
property to <th> and <td> for horizontal dividers:th, td { 2px solid black; }
Use the
selector on <tr> to highlight table rows on mouse over:First name | Last name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
tr:hover {background-color: rgba(174, 233, 61, 0.4);}
First name | Last name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
For zebra-striped tables, use the
selector and add a to all even (or odd) table rows:tr:nth-child(odd) {background-color: rgba(174, 233, 61, 0.6);}
The example below specifies the background color and text color of <th> elements:
First name | Last name | Savings |
---|---|---|
Peter | Griffin | $100 |
Lois | Griffin | $150 |
Joe | Swanson | $300 |
th { background-color: gold; color: purple; }