Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Child selectors

The child selector is represented as a greater than (>) sign. This allows you to assign styles to any tag that is a direct child of the tag. For example:

div.main > ol {margin-left: 1in;}

This example sets a 1” margin on an ordered list that is a direct child of the <div> tag with a class of main. Any ordered list that is nested within a list or a table would not have the 1” margin.

ol > li p {color: green;}

This example combines a descendant selector with a child selector. This example makes a <p> tag that is inside a <li> tag appear in green. The list item must be a child of an <ol> tag.