Change mouse pointer on click

22,385

Use the :active psuedo-class:

.hand:active {
    cursor: url('/imgages/cursor1.gif');
}
Share:
22,385
QAW
Author by

QAW

Updated on December 30, 2021

Comments

  • QAW
    QAW over 2 years

    I'm currently working on a project that involves elements where a custom mouse pointer will be used. The code that I'm using for that function is simple just:

    .hand {
        cursor:url(/images/cursor1.gif);
    }
    

    Now to my question: - I was just wondering (as the title says) if there are anyway that I can make the cursor change to cursor2.gif when you click inside the div-class "hand" (?).

  • QAW
    QAW about 11 years
    It seems to work, but the only problem is that as soon as I click inside .hand cursor2 appears, and disappears just as quick. Here's my CSS: .hand { width: 1500px; height: 500px; background: pink; cursor:url(/images/cursor1.gif), none; } .hand:active { cursor: url(/images/cursor2.gif), none; }
  • original_username
    original_username over 10 years
    The 'ffox' line is required to override a default CSS cursor rule that Mozilla use: "body:not([id])". I just give the body an id if it doesn't already have one. It doesn't need to be 'body_id', it can be anything.
  • Carlos Pinzón
    Carlos Pinzón almost 4 years
    There's a minor typo: 'imgages'.