Forum Moderators: not2easy
<div>
<foo></foo>
<bar></bar>
</div>
If you wanted to color <bar> blue while <foo> was activated, you might try:
div[foo:hover] bar
{
background-color:blue;
}
This is not legal with CSS selectors, but is childs play with XPath's selector syntax. That leaves you three pure CSS options.
div:hover bar
{
background-color:blue;
}
div:hover>bar
{
background-color:blue;
}
div foo:hover+bar
{
background-color:blue;
}
In this case the first two work partially, and may give you what you want, and the last one is perfect. Still, which of these is useful (if any) depends on the structure of the HTML and what you want to achieve.
But, instead of creating a single rule, you can create complex rule sets that sometimes get you where you want to go. The first example, which is the only one that will work in IE, can be made fully functional like this:
div:hover bar
{
background-color:blue;
}
div bar:hover
{
background-color:white;
}
It takes a bit of getting your head round, but you can create rulesets with several selectors canceling other ones out, just to achieve a single effect. And all because CSS does not allow you to non-committal probing (ooh err!) like XPath does.
Dominic.
So, you're stuck between a rock and a hard place. Either you code for compliant browsers (if you can live with the fact that it doesn't work in IE) or you do something else. That "something else" would in this case be onmouseover and onmouseout attributes. That can get really messy, so make sure that you've tested it first.
If you decide to go for an all JavaScript solution, make sure to test in the other browsers as well, and use proper DOM syntax.
However, there's nothing stopping you from implementing a combination of the two. Use the adjacent sibling selector to get the exact effect you want, in compliant browsers. Then use onmouseover stuff to fake a similar behavior in IE. Works like a charm!