我有一个列表,并且有一个点击处理程序:
<ul>
<li>foo</li>
<li>goo</li>
</ul>
如何将鼠标指针更改为手指针(如悬停在按钮上)?现在,当我将鼠标悬停在列表项上时,指针变成了文本选择指针。
我有一个列表,并且有一个点击处理程序:
<ul>
<li>foo</li>
<li>goo</li>
</ul>
如何将鼠标指针更改为手指针(如悬停在按钮上)?现在,当我将鼠标悬停在列表项上时,指针变成了文本选择指针。
当前回答
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指针,但有两种方法:
应用CSS属性cursor:pointer;到元素。(这是光标悬停在按钮上时的默认样式。)应用CSS属性cursor:url(pointer.png);为指针使用自定义图形。如果您希望确保用户体验在所有平台上都是相同的(而不是让浏览器/OS决定指针光标的外观),这可能更可取。注意,如果找不到图像,可以添加回退选项,包括辅助url或任何其他选项,即光标:url(pointer.png,fallball.png,pointer);
当然,这些可以通过以下方式应用于列表项:li{cursor:pointer;},作为class.class{curator:pointer:},或者作为每个元素style=“cursor:ppointer;”的style属性的值。
仅为完整起见:
cursor: -webkit-grab;
它还提供了一只手,当移动图像的视图时,你会知道这只手。
如果您想使用jQuery和mousedown模拟抓取行为,这非常有用。
li:hover {cursor: hand; cursor: pointer;}
只需输入此代码。
li{cursor: pointer;}
您可以在悬停时更改它,也可以只在列表项上指定光标:指针,两者都可以。
ul li {
cursor: pointer;
}
或者
ul li:hover {
cursor: pointer;
}