H153 - Practice Quiz Week 2
- 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:
- p.urgent.warning
Any
pelement with aclassattribute that contains the words "urgent" and "warning". - h1:first-child
Any
h1element that is thefirst-childof its parent element. - p:first-line
Selects the first displayed line of a
pelement. - p:first-child + * > table
Any
tableelement that is a child of any element that immediately follows apelement that is thefirst-childof its parent element. - body:lang(en)
Any
bodyelement that has a language or locale that equals "en" or starts with "en-". - input[type="text"]
Any
inputelement that has atypeattribute that equals "text". - p[class]
Any
pelement that has aclassattribute. - p[class="aside"]
Any
pelement that has aclassattribute that equals "aside". - p[class~="aside"]
Any
pelement that has aclassattribute that contains the word "aside". - p[class|="aside"]
Any
pelement that has aclassattribute that equals "aside" or starts with the word "aside-". - a[href] *
Any element that is a descendant of a
aelement that has ahrefattribute. - a[href="http://www.w3.org/"][title="W3C-external"]
Any
aelement that has ahrefattribute that equals "http://www.w3.org/" and atitleattribute that equals "W3C-external".
- p.urgent.warning
- Explain the difference between div :first-child and div:first-child.
The first selects any element that is the first child of a
divelement (same as div *:first-child), but the second selects anydivelement that is a first-child of its parent. - Construct a single stylesheet that will have the following results for a document, without using attribute selectors:
- Unvisited hyperlinks are colored blue
- Visited hyperlinks are colored gray
- Hyperlinks with focus have a light yellow background
- Hovered hyperlinks are underlined and colored red
- Active hyperinks are boldfaced white text on a navy-blue background
<style type="text/css">
<!--
a:link {color: #00f; background-color: inherit;}
a:visited {color: #aaa; background-color: inherit;}
a:focus {color: inherit; background-color: #fffacd;}
a:hover {color: #f00; background-color: inherit; text-decoration: underline;}
a:active {color: #fff; background-color: navy; font-weight: bold;}
-->
</style> - Write a single rule to accomplish each of the following tasks with the markup that follows (that is, one rule per question). Note that in some cases it may be possible to accomplish a task in multiple ways. In addition, answer the following question: which em elements will be boldfaced by the rule em:first-child {font-weight: bold;}?
so, favorite, there
<body>
<h1>Hel<strong>lo</strong> there!</h1>
<p>Welcome to my Web site. I'm <em>so</em> 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>,
on the date I wrote it.
</div>
</body>
- Put a border around the strong element in the rant (try to use a different selector than in last week's quiz).
p strong:first-child {border: thin solid red;}
- Boldface the word "me" in the footer, and use an attribute selector to do it.
a[href="mepics.html"] {font-weight: bold;}
- Make the e-mail hyperlink purple when it is "unvisited."
a[href="mailto:me@my.web.site"] {color: #f0f; background-color: inherit;}
- Make the hyperlinks in the long list of links turn red when the mouse pointer is moved over them.
li a:hover {color: #f00; background-color: inherit;}
- Put a border around the strong element in the rant (try to use a different selector than in last week's quiz).