I am trying to display sets of images with up and down navigation in form of arrows. I have added
cursor:pointer;
to the arrows on hover to emphasize the clickability. However, when there is no more images in a certain direction, i set the class to disabled.
.disabled
{
cursor:default;
}
However, the hover pseudo class takes precedence here, and changes the cursor to pointer. How can I prevent :hover to set the cursor to pointer when .disabled is set? Is it at all possible?
-
1Setting cursor "what the mouse cursor should look like when pointing here: in a :hover rule "how to style things when pointing here" is rather redundant.Quentin– Quentin2010年07月30日 11:50:35 +00:00Commented Jul 30, 2010 at 11:50
-
@David Dorward Hmm, you lost me there.. If you could rephrase that a bit?Max– Max2010年07月30日 11:55:14 +00:00Commented Jul 30, 2010 at 11:55
-
I expanded on David's point a little in my answer.Andy E– Andy E2010年07月30日 11:57:14 +00:00Commented Jul 30, 2010 at 11:57
-
Cursor only has any impact when the pointer is pointing at the element. :hover only has any impact when the pointer is pointing at the element. So foo:hover { cursor: bar } means "When the pointer is over the element, make the cursor 'bar' when it is over the element". The :hover is pointless.Quentin– Quentin2010年07月30日 11:57:56 +00:00Commented Jul 30, 2010 at 11:57
-
Haha you are totally right. Thanks.Max– Max2010年07月30日 12:00:14 +00:00Commented Jul 30, 2010 at 12:00
2 Answers 2
Add also
.disabled:hover {
cursor: default;
}
1 Comment
Use !important
.
.disabled {
cursor:default!important;
}
IE6's !important
implementation is buggy, so if you need to support it you might just be better off re-ordering your rules to get the required precedence for the .disabled
class.
David Dorward raised an interesting point to note in the comments. Applying a value to cursor in a :hover
pseudo-class is completely redundant. The following to rules have exactly the same effect:
.mylink { cursor:pointer; }
.mylink:hover { cursor:pointer; }
Therefore, you should avoid setting cursor in a pseudo class and stick to
.mylink { cursor:hand; }
2 Comments
hand
is invalid CSS. (That said, !important is a one-use sledgehammer and is almost always the wrong answer (the right answer being "Get your specificity straight")hand
was a MS proprietary value for cursor. I do agree that re-ordering rules is usually the better solution. Thanks for the corrections.