Cursor Pointer on transparent image

Hey, I was wondering if there was a way with css only to only show the cursor: pointer; if the mouse is hovering on the part of an image that is not transparent?
10 Replies
capt_uhu
capt_uhu2w ago
I think you can do this with pointer-events if the image is an SVG: https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events there's also <map> but honestly I haven't used it in forever so I've long forgotten the details: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map
ἔρως
ἔρως2w ago
svg is a better option image maps are interesting, but arent responsive
EasyToKill_ (long break)
my image is not an svg unfortunately ill do it with canvas then
ἔρως
ἔρως2w ago
the worst of all options you can make your image an svg by just wrapping it with an svg tag that should work, as <img> and <image> are kinda like quasi-almost-nearly synonims if it doesnt, use <image>
EasyToKill_ (long break)
so i just do <svg><img></svg> ? or you mean i can save my image as a svg?
ἔρως
ἔρως2w ago
yes, just do the first one if it doesnt work, use <image> both <img> and <image> use the same basic set of attributes (src, width, height, ...) and you can position the <image> with x and y on top of it, you can put a <link> with a shape i think you can use a <path> actually, its <a>, not <link>
ἔρως
ἔρως2w ago
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
ἔρως
ἔρως2w ago
here, a very basic example showing a circle on top of the image the circle is clickable, and has the cursor too it's also perfectly responsive as well - try it also, only the exact area of the circle is clickable if you want to do something similar, you will need to use fill="transparent" it's black because it's the default color and it's visible on top of the image
EasyToKill_ (long break)
ah yes i get it now. Thanks for your time
ἔρως
ἔρως2w ago
you're welcome
Want results from more Discord servers?
Add your server