views:

1439

answers:

5

I have created a CSS class as follows:

div.ycontent .ppclisting { background-color:#cccccc; }
div.ycontent .ppclisting:hover { background-color:#FFE5DF; }

I have applied the above style in one of my page, which is working quite fine in Firefox, IE 7.0+ and in other latest browsers. But When I am applying the same style in another page then its not working.

Can anyone tell me what could be the reason? why its not working in another page.

A: 

Maybe the nested div in the other page doesn't have the class ycontent and/or the element itself isn't class ppclising?

You wrote just what I was typing ;)
victor hugo
+2  A: 

If it's working in one place, but not another place, then either it's not being called correctly or it's not being applied correctly.

Use Firebug, and see what properties the element that should have the styles really have. Then check the classnames for typos. Usually, that'll solve the problem as described.

David Thomas
I alreday checked properties with WEB Developer toolbar (firefox extension), and for the first page it show both .ycontent and .ycontent:hover properties, but for other page it only showing .ycontent class not the .ycontent:hover class ??
Prashant
+1  A: 

Also, in IE6, hover only works on hyperlinks. Keep that in mind.

alex
I know that, that's why I mentioned IE7+ in my question.
Prashant
+1  A: 

I am in agreeance with Brandon.

I will also add..

If you remove the:

div.ycontent

section from your lines, such that it looks like this:

.ppclisting { 
background-color:#cccccc; 
}

.ppclisting:hover { 
background-color:#FFE5DF; 
}

You may find it will work on your other page.

Why? Because you have defined these styles as 'classes'. Classes intend to apply the same style numerous times.

By placing the "div.ycontent" before it, you are essentially 'restricting'/ not utilising the pull potential of CSS classes.

Lycana
yes this was the case he should have right now, the other page didn't have div.ycontent element V-UP
Dels
All pages have the div with class .ycontent
Prashant
+3  A: 

I got the answer why the :hover was not working on another page. Actually on second page the DOCTYPE tag was not added in the HTML page as below,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;

Earlier it was simple <html> tag and due to which :hover on the div was not working. After adding doctype tag as shown above its working for mw,

Thanks to all of you for help.

Prashant
You didn't mention, that you use :hover on a **div**. That could have helped... However, I never heard of the Doctype having influence on this one.
Boldewyn
This also solved the problem for us. Can anyone explain why this fixes the problem?
Robert