Skip Links  

Intermediate CSS Workshop

Selector Matching Exercise

Your mission in this simple exercise is to match the two elements where I have put *** around the text - with one selector - and without affecting any other elements.  Make those two elements red and boldfaced. 

A second paragraph with *** some emphasized text. ***

And a third paragraph with a link.

  1. List item one in second <div>.
  2. List item two.
  3. List item three.

And this is more filler text - in a paragraph in the second <div> - with a *** link ***.

The Markup

Here's a look at the skeleton of that bit of markup above, assuming that it were an entire document.  I have inserted three red asterisks to highlight the elements we want to match.

<body>
<h2></h2>
<div>
<p><em></em></p>
<p><em>***</em></p>
<p><a href="http://www.cbsnews.com"></a></p>
</div>
<div>
<ol>
<li></li>
<li></li>
<li></li>
</ol>
<p><a href="http://www.abc.com">***</a></p>
</div>
</body>

The Document Tree

And here's the doctree image with the elements we want to match highlighted:


document tree image

The Solution

Or A Solution.  If I wanted to match those elements, here's the thought process I would go through and the steps I would take to build the selector:

And it works!

Remember that this is just one possible solution.  There are others.  It's the process that's important - how you get to a match of the two elements.  It's important to find a way to match two different elements with one selector, using the selectors and combinators covered in this week's reading.  It's a question of (a) what makes these two elements alike?  And (b) what makes both of them (together - sort of as one) unique?  This should help with questions 3, 4 and 5 on the quiz.