我有一个列表,并且有一个点击处理程序:

<ul>
  <li>foo</li>
  <li>goo</li>
</ul>

如何将鼠标指针更改为手指针(如悬停在按钮上)?现在,当我将鼠标悬停在列表项上时,指针变成了文本选择指针。


当前回答

我认为在JavaScript可用时只显示手/指针光标是明智的。因此,人们不会觉得自己可以点击不可点击的东西。

为了实现这一点,您可以使用JavaScript库jQuery向元素添加CSS,如下所示

$("li").css({"cursor":"pointer"});

或者将其直接链接到单击处理程序。

或者当modernizer与<html class=“no js”>结合使用时,CSS将如下所示:

.js li { cursor: pointer; }

其他回答

li:hover {cursor: hand; cursor: pointer;}

CSS:

.auto            { cursor: auto; }
.default         { cursor: default; }
.none            { cursor: none; }
.context-menu    { cursor: context-menu; }
.help            { cursor: help; }
.pointer         { cursor: pointer; }
.progress        { cursor: progress; }
.wait            { cursor: wait; }
.cell            { cursor: cell; }
.crosshair       { cursor: crosshair; }
.text            { cursor: text; }
.vertical-text   { cursor: vertical-text; }
.alias           { cursor: alias; }
.copy            { cursor: copy; }
.move            { cursor: move; }
.no-drop         { cursor: no-drop; }
.not-allowed     { cursor: not-allowed; }
.all-scroll      { cursor: all-scroll; }
.col-resize      { cursor: col-resize; }
.row-resize      { cursor: row-resize; }
.n-resize        { cursor: n-resize; }
.e-resize        { cursor: e-resize; }
.s-resize        { cursor: s-resize; }
.w-resize        { cursor: w-resize; }
.ns-resize       { cursor: ns-resize; }
.ew-resize       { cursor: ew-resize; }
.ne-resize       { cursor: ne-resize; }
.nw-resize       { cursor: nw-resize; }
.se-resize       { cursor: se-resize; }
.sw-resize       { cursor: sw-resize; }
.nesw-resize     { cursor: nesw-resize; }
.nwse-resize     { cursor: nwse-resize; }

也可以将光标设置为图像:

.img-cur {
   cursor: url(images/cursor.png), auto;
}

只需使用CSS设置自定义光标指针


/* Keyword value */
cursor: pointer;
cursor: auto;

/* URL, with a keyword fallback */
cursor: url(hand.cur), pointer;

/* URL and coordinates, with a keyword fallback */
cursor: url(cursor1.png) 4 12, auto;
cursor: url(cursor2.png) 2 2, pointer;

/* Global values */
cursor: inherit;
cursor: initial;
cursor: unset;

/* 2 URLs and coordinates, with a keyword fallback */

cursor: url(one.svg) 2 2, url(two.svg) 5 5, progress;

demo

注意:光标支持许多格式图标!

例如.cur、.png、.svg、.jpeg、.webp等

li:悬停{光标:url(“https://cdn.xgqfrms.xyz/cursor/mouse.cur“),指针;颜色:#0f0;背景:#000;}/*li:悬停{光标:url(“../icons/hand.cur”),指针;}*/李{高度:30px;宽度:100px;背景:#ccc;颜色:#fff;边距:10px;文本对齐:居中;列表样式:无;}<ul><li>一个</li><li>b级</li><li>c类</li></ul>

refs

https://developer.mozilla.org/en-US/docs/Web/CSS/cursor

对于完整的跨浏览器,请使用:

cursor: pointer;
cursor: hand;

Use:

ul li:hover{
   cursor: pointer;
}

有关更多鼠标事件,请检查CSS光标属性。