CSS TutorialLesson #63

Table Styling

To add some more space between the inner borders and the content in a table, use the

CSS Table Padding

To add some more space between the inner borders and the content in a table, use the padding property on <td> and <th> elements:

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
th, td
{

padding: 10px;
  text-align: left;

}

CSS Horizontal Dividers

To create horizontal dividers for a table, add the border-bottom property to <th> and <td> elements:

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
th, td {
  border-bottom: 1px solid #ddd;
}

CSS Hoverable Table

Use the CSS :hover selector on <tr> to highlight table rows on mouse over:

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
tr:hover {background-color: coral;}

CSS Zebra-striped Table

For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd) table rows:

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
tr:nth-child(even) {background-color: #f2f2f2;}

CSS Table Color

The example below specifies a background color and a text color for the <th> elements:

First NameLast NameSavings
PeterGriffin$100
LoisGriffin$150
JoeSwanson$300

Example

Example Code

css
Try it Yourself
th {
  background-color: #04AA6D;
  color: white;
}


Interactive Code Examples

CSS Example 1

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 2

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 3

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 4

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 5

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview: