Why can't I change a cursor in standards mode?

2019-08-15 04:10发布

问题:

Example (tested in Chrome):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML><HEAD>
<TITLE>testing cursor change</TITLE>
</HEAD>
<BODY>
<p style="cursor: url('a/web/images/catcursor.cur')" >only works in quirks mode</p>
</BODY></HTML>

If I change the Doctype to 1.0 it reports being in standards mode and the cursor no longer changes. How do I get round this?

Why I want to: I am making a web based game, and at one point a cat attacks the cursor, so I want the pointer to look distressed.

回答1:

You'll need to specify a preset cursor:

<p style="cursor: url('a/web/images/catcursor.cur'), default">

The preset value is required in order for the cursor property to be valid. Without it, it's invalid, so browsers in standards mode need to ignore it entirely.



标签: html css cursor