Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

CSS

CSS Direct Child Selector

Notes:

CSS – Child Selector (>) / (Direct Child Selector):
It selects any HTML element targeted by the selector written after the greater than character, which is a direct child of the any HTML element targeted by the selector written before the greater than character.

Syntax of CSS rule-set / rule:
selector
{
declaration list;
}

To implement child selector, in place of selector; we write selectors one beside another separated by the greater than character.

Syntax of Child Selector:
selector1 > selector2
{
declaration list;
}
It selects any HTML element targeted by selector2, which is direct child of any HTML element targeted by selector1

Ex:
div > p
{
border:2px solid red;
}
It selects any p element, which is direct child of any div element

Interview Questions:

1. Which symbol indicates direct child selector in CSS?
a. hash
b. plus
c. dot
d. greater than
Answer: d