Forum Moderators: not2easy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hover and last-of-type</title>
<style type="text/css">
/*Make this look like a real-world news page */
#news {
width: 38em;
border:0.1em solid #eee;
padding:1em;
margin:0 auto;
}
p {
border:0.08em dashed #000;
padding:1em;
width:33em;
margin: 1em auto;
line-height:1.6;
}
ul {
margin:0;
padding:0.2em;
list-style-type:none;
background-color:#eee;
width:7em;
border:0.1em #aaa;
}
li {line-height:1.6em;border-bottom:0.08em dashed #000;}
li:last-of-type {border-bottom:none;}
ul + p {margin-top:2em;}
/*Getting to the purpose */
p a, li a {
text-decoration:none;
padding:0.1em 0.2em;
color:#000;
background-color:#eee;
}
p a:hover, li a:hover {background-color:#aaa;}
p a:last-of-type {
display:block;
width:7em;
position:relative;
left:85%;
color:#fff;
background-color:#000;
text-align:center;
padding:0.2em;
}
/*The example */
p a:last-of-type:hover {
background-color:#eee;
color:#000;
font-weight:bold;
}
/*Because this was too much fun*/
p a[title~="Biography"]:hover::after {
position:absolute;
margin:5px 0 0 10px;
height:80px;
width:80px;
border:0.02em solid #aaa;
text-align:center;
color:#000;
}
p a[title~="Fred's"]:hover::after {
background: #eee url(fred.jpg) 0 30px no-repeat;
content:"Fred";
}
p a[title~="Freda's"]:hover::after {
background: #eee url(freda.jpg) 0 30px no-repeat;
content:"Freda";
}
p:target {border:0.6em solid #eee;}
/*Easter egg */
p:last-of-type:target:hover::after {
display:block;
content:"Still reading? Don't forget to visit the archives!";
font-size:1.2em;
}
</style>
</head>
<body>
<div id="news">
<h2>In the wild ...</h2>
<ul>
<li><a href="#first">Breaking News</a></li>
<li><a href="#last">Oldest</a></li>
<li><a href="example.com/archive">News Archive</a></li>
</ul>
<p id="first">The inside details on <a href="#" title="Fred's Biography">Fred</a>, the <a href="#">team</a> and <a href="#">Project X</a>. (The official report is in <a href="#">Resources</a> and a movie of the formal presentation in <a href="#">Meetings</a>.)
<a href="#" title="The full story">Read More ...</a>
</p>
<p><a href="#" title="Freda's Biography">Freda</a> tells what <i>really </i> happens when you mix one <a href="#" title="Fred's Biography">Fred</a>, two ### and just a little-too-much ### ....
<a href="#" title="The full story">Read More ...</a>
</p>
<p><a href="#" title="Freda's Biography">Freda</a> tells what <i>really </i> happens when you mix one <a href="#" title="Fred's Biography">Fred</a>, two ### and just a little-too-much ### ....
<a href="#" title="The full story">Read More ...</a>
</p>
<p id="last"><a href="#" title="Freda's Biography">Freda's</a> report on <a href="#">January</a> activities in <a href="#">some place</a>.
<a href="#">Read More ...</a>
</p>
</div>
</body>
</html>
#content #profile div.side div:last-of-type a
... select the last divisible element and then select any anchor inside since any divisible element that has an anchor will only have a single anchor.As said, I don't get to use these selectors much, but have found (as you did), they provide an opportunity to really think about the structure of the html and relationships between elements on the page - and that's got to be good for code.