Using Contextual Selectors

You can use contextual selectors to specify the style of elements that appear within other elements. For example, you might want an element to appear one way when it's by itself, but another way when enclosed in another element. Here's how that might look. In this case, I'm specifying that when used inside <P> elements, the <U> element must underline its enclosed text:

Listing . ch09_12.css
 
TITLE {display: block; font-size: 24pt; font-weight: bold;
text-align: center; text-decoration: underline}
AUTHOR {display: block; font-size: 18pt; font-weight: bold;
text-align: center}
SECTION {display: block; font-size: 16pt; font-weight: bold;
text-align: center; font-style: italic}
P {display: block; margin-top: 10}
P U {text-decoration: ...

Get Real World XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.