views:

3999

answers:

8

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.

+8  A: 

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.

Jon Galloway
A: 

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.

Haacked
+1  A: 

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

toast
"specifically trying to change the cursor" does not require JavaScript. Just use this CSS rule:cursor:pointer;
Liam
But to "simulate the hover pseudo-class for non-Anchor tags in IE6" simply does, and that's the question I was answering. When people are looking for an answer to "IE non-Anchor hover", "use 'cursor:pointer'" isn't going to be helpful at all.
toast
Livingston Samuel
A: 

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.

YonahW
+1  A: 

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.

Joseph Pecoraro
+5  A: 

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>
Nathan Peretic
I voted you up because you read the question, which seems to be a different approach to the other users :)
Liam
Oh and I tested this in IE6, IE7, Firefox 3, Safari and Google Chrome and of course it works perfectly.
Liam
A: 

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

GateKiller
+2  A: 

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

Sören Kuklau