child css selector code example
Example 1: nth-child() css
li:nth-child(2) {
color: lime;
}
:nth-child(4n) {
color: lime;
}
Example 2: child css
p:nth-child(2)
{
background: red;
}
Example 3: css select descendant with class
Select an element with the ID "id" and the class "class":
#id.class {
}
example:
<div>
<strong id="id" class="class">
Foobar
</strong>
<strong class="class">
Foobar
</strong>
</div>
=> Will select the first <strong> element
Select all elements with the class "class",
which are decendents of a element with an ID of "id":
#id .class {
}
example:
<div id="id">
<strong class="class">Foobar</strong>
</div>
=> Will select the <strong> element
Example 4: how to use child selectors in css
ul li { margin: 0 0 5px 0; }
ul > li { margin: 0 0 5px 0; }