Question

What is the simplest and most elegant way to simulate the hover pseudo-class for non-Anchor tags in IE6?

I am specifically trying to change the cursor in this instance to that of a pointer.

Was it helpful?

Solution

I would say that the simplest method would be to add onmouseover/out Javascript functions.

OTHER TIPS

I think the simplest way is to use the hover.htc approach. You add the hover.htc file to your site, then reference it in your stylesheet:

body { behavior:url("csshover.htc"); }

If you want to keep things as clean as possible, you can use IE conditional comments so that line is only rendered users with IE6.

Regarding your request -- I am specifically trying to change the cursor in this instance to that of a pointer -- the easiest way is to specify cursor:pointer in your css. I think you will find that works in IE 6.

Try this to verify (where div can be any element):

<div style="background:orange; cursor:pointer; height:100px; width:100px;">
    Hover
</div>

Another alternative that will fix many more issues in one go is to use IE7.js.

Another approach, depending on what the item is, is to add a non link anchor and set its display to block. Either put the anchor within or surrounding the item you want the pseudo hover behavior on.

Aside:

I actually already needed to swap the image anyhow

Make sure you take a look at Image Sprites. Sometimes its much nicer to use one image and "shift" the image then to use two separate images and "toggle" or "swap" between them. In my experience its been much nice when as user interacts with it is sometimes an advantage that there is a single request for the 1 image then multiple requests for multiple images.

I liked the mouseover/out best since I actually already needed to swap the image anyhow. I really should have thought of doing this with javascript to begin with.

Thanks for the quick answers.

@Joseph

Thanks for that link. I had never heard of this technique before and really like the idea.

I will definitely try that out and see how I fare with it.

If your willing to use JQuery, I would use Set Hover Class for Anything technique.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top