View Full Version : Dynamic ul to change color on hover/click.

11-24-2008, 05:43 PM
Hi everyone,

I can make a dynamic ul change to bold on hover/click with a select class in css, but I can't get it to change color. Why is that?

Here is some code:-

echo "<ul>";

$query = "SELECT * FROM category ORDER BY categoryId DESC";
$result = mysql_query($query, $connection);
while($category = mysql_fetch_array($result))
echo "<li";
if($category['categoryId'] == $sel_product )
echo " class=\"selected\"";
echo "><a href=\"display.php?categoryId=" .urlencode($category['categoryId']).

echo "</ul>";

and in css:-

.selected {
font_weight: bold;
color: #FF0000;

I'd really appreciate any help.


11-24-2008, 06:25 PM
Write out style for all 4 states:
a.selected:link {}
a.selected:visited {}
a.selected:hover {}
a.selected:active {}

Also 'font_weight' is wrong. The property is spelled 'font-weight'

If this does not work for you you need to be able to give us the generated page, not the php file. Preferably by URL :)

11-25-2008, 08:37 PM
Thanks very much, domedia.

That's helped a lot. Each link now changes color when selected, but not on hover.

I'll try to put the page up tomorrow.

Thanks again.

11-25-2008, 10:29 PM
Yeah, let us know. It's so much easier to tell you exactly what to do when we know the context.

11-25-2008, 11:43 PM
Hey domedia,

I've just got the hover working also. I'm not too sure if it's a sound solution, I mean maybe somewhere down the road it will throw up some flaws, but as far as I can tell its good.

I put:-

echo "class = \"unselected\"";

after the 'if' statement in my first post, and then added this to your code:-

a.unselected:hover {
color: #ff0000;

So now I get red links on hover and red links when selected.

Thanks again domedia for sorting things out.