Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

11. Divs and Spans: Advanced Web Constru... > What we need is a way to select desc...

What we need is a way to select descendants

What we’re really missing is a way to tell CSS that we want to only select elements that descend from certain elements, which is kinda like specifying that you only want your inheritance to go to the children of one daughter or son. Here’s how you write a descendant selector.

image with no caption

Now the only problem with this rule is that if someone created another <div> in the “lounge.html” file, they’d get black <h2> text, even if they didn’t want it. But we’ve got an id on the elixirs <div>, so let’s use it to be more specific about which descendants we want:

image with no caption

Sharpen your pencil

Your turn. Write the selector that selects only <h3> elements inside the elixirs <div>. In your rule, set the color property to #d12c47. Also label the elements in the graph below that are selected.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial