04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

more on selecting children<br />

Sharpen your pencil<br />

h1<br />

454 Chapter 11<br />

Your turn. Write the selector that selects only elements inside the elixirs .<br />

In your rule, set the color property to #d12c47. Also label the elements in the graph<br />

below that are selected.<br />

html<br />

body<br />

h2<br />

Q: Descendant usually means child,<br />

grandchild, great-grandchild. Here, we’re<br />

just selecting the child descendants,<br />

right?<br />

A: That’s a really good point.<br />

The selector “#elixirs h2” means ANY<br />

descendant of elixirs, so the could be<br />

a direct child of the or nested down<br />

inside a or another nested<br />

(making it a grandchild) and so on.<br />

So a descendant selector selects any <br />

nested inside an element, no matter how<br />

deeply it is nested.<br />

h2<br />

div id=”elixirs”<br />

h3<br />

h3<br />

h3<br />

there are no<br />

Dumb Questions<br />

Q: Well, is there a way to select a<br />

direct child?<br />

A: Yes. For example, you could use<br />

“#elixirs > h2”, to select only if it is<br />

the direct child of an element <strong>with</strong> an id of<br />

“elixirs”.<br />

Q: What if I need something more<br />

complex, like an that is the child of<br />

a that is in elixirs?<br />

div id=”calendar”<br />

h1<br />

h2 h3<br />

A: It works the same way. Just use<br />

more descendants, like this:<br />

#elixirs blockquote h2 {<br />

color: blue;<br />

}<br />

This selects any elements that<br />

descend from s that descend<br />

from an element <strong>with</strong> an id of “elixirs”.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!