2

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?

asked Jul 30, 2010 at 11:44
5
  • 1
    Setting 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. Commented Jul 30, 2010 at 11:50
  • @David Dorward Hmm, you lost me there.. If you could rephrase that a bit? Commented Jul 30, 2010 at 11:55
  • I expanded on David's point a little in my answer. Commented 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. Commented Jul 30, 2010 at 11:57
  • Haha you are totally right. Thanks. Commented Jul 30, 2010 at 12:00

2 Answers 2

3

Add also

.disabled:hover {
 cursor: default;
}
answered Jul 30, 2010 at 11:46
Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfectly! Thanks man. (accepting answer when I can, some time limit)
1

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; }
answered Jul 30, 2010 at 11:46

2 Comments

IE6 does support !important (although there are some bugs relating to it) and 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")
@David: you're quite right, I forgot that hand was a MS proprietary value for cursor. I do agree that re-ordering rules is usually the better solution. Thanks for the corrections.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.