H153 - Practice Quiz Week 1
- Selectors can be described in a fairly straightforward way,as long as you work backwards. For example, the selector body div > * can be described as "any element that is a child of a 'div' that is a descendant of the 'body' element."
Describe the following selectors:- h1 em
Any
emelement that is a descendant of ah1element. - html body p
Any
pelement that is a descenant of abodyelement that is a descendant of ahtmlelement. - div *
Any element that is a descendant of a
divelement. - h1 > *
Any element that is a child of a
h1element. - div + ul
Any
ulelement that immediately follows adivelement. - body > h1 + p
Any
pelement that immediately follows ah1element that is a child of abodyelement. - body > div > * h3 + *
Any element that immediately follows an
h3element that is a descendant of any element that is a child ofdivthat is a child of abodyelement.
- h1 em
- Assume the following markup, which cannot be changed in any way:
<body>
<h1>Hel<strong>lo</strong> there!</h1>
<p>Welcome to my Web site. I'm <strong>so</strong>
glad you're here! On this site you can find:
</p>
<ul>
<li><a href="mepics.html">Pictures of me</a></li>
<li><a href="fluffpics.html">Pictures of my cat Fluffy</a></li>
<li><a href="poetry.html">My poetry</a></li>
<li><a href="favlinks.html">My <em>favorite</em> Web sites</a></li>
</ul>
<div class="rant">
<p>
The other day someone wrote telling my site was lame.
I <strong>hate</strong> that! After all,
if you don't like the Web site, don't come here. I'm
proud of my cat and there's nothing wrong with naming
a mynx Fluffy anyway.
</p>
<p>
So <em>there</em>.
</p>
</div>
<p>
If you want, e-mail me at
<a href="mailto:me@my.web.site">me@my.web.site</a>,
but <em>not</em> if you're going to complain.
</p>
<p>Have a nice day!</p>
<div class="footer">
All content copyright <a href="mepics.html">me</a>.
</div>
</body>
Write rules to accomplish each of the following tasks, one rule per answer. Note that in some cases it may be possible to accomplish a task in multiple ways. Try to be as precise as possible with your selectors.
- Make all strong elements boldfaced.
strong { font-weight: bold; }
- Only boldface the strong element in the rant.
div.rant strong { font-weight: bold; }
- Make the rant red (your choice of which red).
div.rant { color: #F00; background-color: inherit; }
- Boldface the word "me" in the footer.
div.footer a { font-weight: bold; }
- Put a border around only those elements that are children of the body element.
body > * { border: thin solid #000; }
- Set to zero the top margin of only the paragraph which starts "Welcome to my Web site."
h1 + p { margin-top: 0; }
- Put a border around only those paragraphs that are grandchildren of the body element.
body > * > p { border: thin solid #000; }
- Put a border only those elements that are at least grandchildren of the body element, but none of its children. (Hint: contemplate the space between the stars to find an answer.)
body * * { border: thin solid #000; }
- Boldface only the paragraph which says "So there." (Hint: use of a particular selector would be a plus in this situation.)
div.rant > p + p { font-weight: bold; }
- Make all strong elements boldfaced.