:nth-child examples
by firegroove
HTML
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link rel="stylesheet" type="text/css" href="styling.css">
<title>Examples of CSS3</title>
<body>
<h1>Alternate Rows</h1>
<div id="accordion">
<h3>SECTION 1</h3>
<h3>SECTION 2</h3>
<h3>SECTION 3</h3>
<h3>SECTION 4</h3>
<h3>SECTION 5</h3>
<h3>SECTION 6</h3>
<h3>SECTION 7</h3>
<h3>SECTION 8</h3>
<h3>SECTION 9</h3>
<h3>SECTION 10</h3>
</div>
<br>
CSS
body {
margin: 5px;
}
h1 {
font-size: 30px;
font-family: Helvetica, sans-serif;
padding: 20px 0px;
}
h3{
font-family: Helvetica, sans-serif;
margin-left:1em;
margin-bottom:0.25em;
text-align:left;
color: #fff;
padding:5px;
width:100px
}
ul {
margin: 0 0 10px 25px;
list-style: disc;
}
#accordion h3:nth-child(odd) {
background-color: #0096d6;
}
#accordion h3:nth-child(even) {
background-color: #c0d0db;
}
table {
width: 80%;
margin-left: 10px;
border-collapse: collapse;
}
.second-example td {
padding: 8px;
line-height: 18px;
text-align: left;
vertical-align: top;
border-top: 1px solid #dddddd;
}
.second-example td:first-child {
border-left: 1px solid #dddddd;
}
.second-example td:last-child {
border-right: 1px solid #dddddd;
}
.second-example tr:nth-child(2n+4) {
background-color: #f3f3f3;
}
.second-example tr:last-child {
border-bottom: 1px solid #dddddd;
}