close window

Contextual selectors are very selective.

This example shows how to target a specific tag using the document hierarchy.

Tags only need to be descendants in the order stated in the selector; other tags can be in between and the selector still works.

In this example, the word very in the first sentence is not orange because it is in a H1 tag, not a P tag. The word specific in the second sentence is orange because it is in a P tag. The phrase order stated in the third sentence is orange because it is a descendant of a P tag, though it is two levels below it.

p em {color: orange;}
<h1>Contextual selectors are <em>very</em> selective. </h1>   <p>This example shows how to target a <em>specific</em> tag using the document hierarchy. </p>   <p>Tags only need to be descendants <span> in the <em>order listed</em> in the selector </span>; other tags can be in between and the selector still works. </p>