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

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

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


当前回答

Use:

li:hover {
    cursor: pointer;
}

可以在此处查看当前HTML规范的其他有效值(哪只手不是)。

其他回答

仅为完整起见:

cursor: -webkit-grab;

它还提供了一只手,当移动图像的视图时,你会知道这只手。

如果您想使用jQuery和mousedown模拟抓取行为,这非常有用。

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

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

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

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

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

.js li { cursor: pointer; }

您可以使用以下代码:

li:悬停{光标:指针;}

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;
}

只需执行以下操作:

li { 
  cursor: pointer;
}

我将其应用于您的代码,以了解其工作原理:

李{光标:指针;}<ul><li>食品</li><li>粘的,粘的</li></ul>

注意:也不要忘记,您可以使用自定义光标创建任何手形光标,您可以创建像这样的最喜欢的手形图标,例如:

第二部分{显示:块;宽度:400px;高度:400px;背景:红色;光标:url(http://findicons.com/files/icons/1840/free_style/128/hand.png)4 12,自动;}<div></div>