w3resource
HTML exercises

HTML CSS Exercise: Zebra table

Solution:

HTML Code:

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset=utf-8>
<title>HTML CSS exercise - CSS3 Zebra Striping a Table</title>
<style type="text/css">
table {
border:1px solid silver
}
th {
background-color: #ccc;
}
tbody tr:nth-child(even) {
background-color: #abe113;
}
</style>
</head>
<body>
<table>
<tr><th>Id</th><th>Name</th><th>Major</th></tr>
<tr><td>1001</td><td>Gopl Murthy</td><td>Physics</td></tr>
<tr><td>1002</td><td>Joy Sen</td><td>Economics</td></tr>
<tr><td>1003</td><td>Chandu Yadav</td><td>Chemistry</td></tr>
<tr><td>1004</td><td>Shalini Gupta</td><td>Zoology</td></tr>
<tr><td>1004</td><td>Vivek Kumar</td><td>Math</td></tr>
<tr><td>1004</td><td>Sameer Ali</td><td>Botany</td></tr>
</table>
</body>
</html>

Live Demo:

See the Pen zebra-table-answer by w3resource (@w3resource) on CodePen.


Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
YesYesYesYesYes

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming