Forum Moderators: not2easy

Message Too Old, No Replies

whatever:hover JS in your CSS

no extra script, no behavior file

         

SuzyUK

11:03 am on Mar 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interesting find recently was the ability to add the equivalent of the Suckerfish Javascript directly to the CSS.

Was thinking that those who don't like using (or can't use) the all encompassing - whatever:hover behaviour file [xs4all.nl] - it perhaps still offers a "keep it in the CSS" solution.

I like it for quick testing but might use it more as it can go in the "legacy" IE file or in the main css file via a legacy hack.

Downside over the behaviour file is that you need to use extra class name distinctions.rules in the CSS like Suckerfish

Upside over Suckerfish is that you can easily incorporate more than one menu per page.


* html li {
behavior: expression(
this.onmouseover = new Function("this.className += ' hover'"),
this.onmouseout = new Function("this.className = this.className.replace(' hover','')"),
this.style.behavior = null
);
}

your css rule might look something like this:

ul#nav li:hover, ul#nav [blue]li.hover[/blue] {property: value;}

the code above will apply the hover behaviour to all <li>'s in the site, or you can narrow it down to just your required menus using the usual more specific selector rules. e.g.

* html #nav1 li, * html #nav2 li {
behavior:expression(...);
}

The * html is also optional and will apply it only to IE6 and below which is all that needs it - or you could drop that part and simply put it in a Conditional Comment.

As far as I can see, you don't have to use "behavior" as the property but it seems fair to me to use an IE proprietary property for an IE proprietary Dynamic Expression?

It might need hiding from IE/Mac, I don't know, if so that would be the downside to putting it in the main CSS file with the hack - but a Conditional Comment would also take care of that..

What do you all think any other downsides/upsides pros/cons, thoughts appreciated

Suzy

[edit] sp: note to self - I mustn't spell 'behavior' as 'behaviour' in code :o [/edit]

[edited by: SuzyUK at 11:08 am (utc) on Mar. 15, 2007]

thesheep

5:12 pm on Mar 15, 2007 (gmt 0)

10+ Year Member



Interesting. But I'm not sure what advantage this has over the HTC file. It seems to be a bit more complicated to implement.

On the other hand, I actually almost never use the HTC method, because for some reason I don't like it. Suckerfish seems cleaner. But I hadn't thought about the case where you need to apply it more than once.