Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the cursor in the element's default styles, or in element:hover?

Is there any practical difference between the following two?

button {
  cursor: pointer;
}

And:

button:hover {
  cursor: pointer;
}

The MDN docs specifically state that:

The cursor CSS property specifies which mouse cursor to display when the mouse pointer is over an element.

So, is there any real difference? Should one be preferred over the other, or are they interchangeable?

like image 560
Lucas Avatar asked Jul 16 '18 08:07

Lucas


People also ask

How do I make my cursor hover?

You can simply use the CSS cursor property with the value pointer to change the cursor into a hand pointer while hover over any element and not just hyperlink. In the following example when you place the cursor over the list item, it will change into a hand pointer instead of the default text selection cursor.

What is the default cursor CSS?

The cursor property of CSS allows you to specify the type of cursor that should be displayed to the user. One good usage of this property is in using images for submit buttons on forms. By default, when a cursor hovers over a link, the cursor changes from a pointer to a hand.

How do I change my cursor style?

To change how the mouse pointer looks , and then clicking Control Panel. In the search box, type mouse, and then click Mouse. Click the Pointers tab, and then do one of the following: To give all of your pointers a new look, click the Scheme drop-down list, and then click a new mouse pointer scheme.


Video Answer


1 Answers

Yes there is a difference, the first is defined when CSS is loaded but the second one will be defined only on the :hover. Visually we may not see a difference, but if you use an image as a cursor you may have a small delay if you define it on hover since you need to wait for image load.

button:hover {
  cursor:url(https://picsum.photos/90/90?image=1069) 5 5, help;
}
<button>wait for loading</button>

For the second example the image will be loaded before hovering (you can check the network tab of your browser to notice this):

button {
  cursor:url(https://picsum.photos/90/90?image=1062) 5 5, help;
}
<button>no need to wait for loading</button>

So better use the second one to avoid any delay and have the cursor ready when needed.

like image 78
Temani Afif Avatar answered Oct 21 '22 19:10

Temani Afif