Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS change custom cursor image origin (hotspot) to center

I want to use a custom image for a cursor.

This is fine, but from what I can see - the origin (tip of arrow) is by default at the top-left point of my image.

How can I set the origin to be the center of my image.

Here is a demo snippet to demonstrate the problem

div {    width: 600px;    height: 100px;    background: pink;    cursor: url(http://placehold.it/50x30), auto  }
<div>the cat in the hat<br> the cat in the hat<br> the cat in the hat<br> the cat in the hat</div>

Notice that when I try to select the text - it selects from the top-left of the image.

like image 827
Danield Avatar asked Oct 24 '13 08:10

Danield


People also ask

How to define a custom position for the cursor hotspot?

You can define a custom position for the cursor hotspot by adding x & y coordinates for where the hotspot should be in the provided custom image.

How to customize cursors in WordPress?

Customizing cursors is an easy way to add an extra flourish to your site when needed. To specify the cursor appearance, use the CSS cursor property, which is used to change the mouse cursor type on elements.

How do I change the cursor appearance in CSS?

For specifying the cursor appearance use the CSS cursor property. This property is used to change the mouse cursor type on elements. It can be useful in websites where different actions should be done rather than just clicking.

How do I create a custom cursor hotspot in SVG?

You can define a custom position for the cursor hotspot by adding x & y coordinates for where the hotspot should be in the provided custom image. Note that, when using svg cursors, it’s important that your svg has width & height values on the root svg element, or else your cursor won’t show.


Video Answer


2 Answers

One solution would be to move the position of your image to match the mouse pointer

cursor: url(image) [x y|auto]; 

Doesn't respond to the question but this is working

HTML

div {     width: 600px;     height: 100px;     background: pink;     cursor: url(http://placehold.it/50x30) 25 15, auto; } 
like image 174
Romain Avatar answered Sep 29 '22 02:09

Romain


You can set it by:

cursor:url(http://placehold.it/50x30) 25 15, auto; 

The two parameters I added set the center of your cursor.

like image 31
Igle Avatar answered Sep 29 '22 03:09

Igle