View Full Version : CSS - Simple hover question!

02-22-2008, 10:07 PM
Ok - this is going to sound stupid, but if you look at the code below, why does it only work if I have it like this?

I'm trying to make the first line turn gray when hovering (but not the second line!)

From what I read, I would assume that you need to specify the p as in:

p#pid a:link
p#pid a:visited

But if I do that, the code doesn't work. Can somebody explain this to me? Thanks :)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css" title="currentStyle" media="screen">
p#pid a:hover {
color:#999999; /* Gray */
#pid a:link {
color:#ffff00; /* Yello */
#pid a:visited {
color:#000000; /* Black */
<div id="divid">
<p id="pid">This is a test <a href="#">Click</a></p>
<p id="p2id">This is another test <a href="#">Click 2</a></p>

02-22-2008, 10:10 PM
OK - never mind - I found the answer - hover must come after :link and :visited. :S