使用HTML/UTF-8字符作为光标

use*_*219 5 html css utf-8

我希望能够在图像悬停时使用双箭头字符作为光标.我可以只将图像添加为自定义光标吗?

cursor: url(images/my-cursor.png), auto;
Run Code Online (Sandbox Code Playgroud)

http://designerstoolbox.com/designresources/html/

Cod*_*rPi 16

这是一个内联SVG的解决方案:

您可以根据需要调整文本(字符)的高度和宽度.您可能还想更改不同字符的文本的y.

html {height:100%;}
body {width:100%;height:100%;margin: 0;
  
  /* only this is relevant */
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="30" style="font-size: 20px;"><text y="15">¶</text></svg>'), auto;
  
}
Run Code Online (Sandbox Code Playgroud)

虽然这是纯CSS,但您也可以制作HTML5-Canvas并使用JavaScript在其上绘制文本:

var canvas = document.createElement("canvas")
canvas.width = 10
canvas.height = 15
var context = canvas.getContext("2d")
context.font = "20px 'sans serif'"
context.fillText("¶", 0, 13)
document.body.style.cursor = "url('" + canvas.toDataURL() + "'), auto"
Run Code Online (Sandbox Code Playgroud)
html {height:100%;}
body {width:100%;height:100%;margin:0;}
Run Code Online (Sandbox Code Playgroud)