138
Use Contextual Selectors ........................................
2 Within the style sheet, type
a parent element or ID and
its child element, separated
by a space.
1 In your editor, open a page
that contains an embedded
style sheet.
Use Contextual Selectors
A
ny style can be applied anywhere on your page with the appropriate use of class or ID selectors, but
at times this can become needlessly cumbersome. For example, if you wanted to apply a particular
style to each item of a long list, you might need to add a class attribute to every one of the items. A
simpler, cleaner solution is to use a contextual selector, which allows you to target an element based
on its position within another element. With a contextual selector, you could apply the desired style to
the list items by referencing their position within another element, such as a div with an ID.