xxxxxxxxxx
<!DOCTYPE html>
<html>
<head>
<style>
/* Selects the second element of div siblings */
.out > :nth-child(1) .myclass {
background: red;
}
.out > :nth-child(2) .myclass {
background: green;
}
.out > :nth-child(3) .myclass {
background: yellow;
}
</style>
</head>
<body>
<div class="out">
<div>
<div>
<div class="myclass">
<p>This is some text.</p>
</div>
SOME
</div>
SOME 2
</div>
<div>
<div>
<div class="myclass">
<p>This is some text.</p>
</div>
SOME
</div>
SOME 2
</div>
<div>
<div>
<div class="myclass">
<p>This is some text.</p>
</div>
SOME
</div>
SOME 2
</div>
</div>
</body>
</html>
xxxxxxxxxx
/* Selects the second <li> element in a list */
li:nth-child(2) {
color: lime;
}
/* Selects every fourth element
among any group of siblings */
:nth-child(4n) {
color: lime;
}
xxxxxxxxxx
/* Selects the second <li> element in a list */
li:nth-child(2) {
color: lime;
}
/* Selects every fourth element
among any group of siblings */
:nth-child(4n) {
color: lime;
}
xxxxxxxxxx
.first span:nth-child(2n + 1),
.second span:nth-child(2n + 1),
.third span:nth-of-type(2n + 1) {
background-color: tomato;
}
xxxxxxxxxx
p:nth-child(3){
background: #05ffb0;
border: 1px solid;
padding: 5px;
}