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

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

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


当前回答

随着时间的推移,正如人们所提到的,您现在可以安全地使用:

li { cursor: pointer; }

其他回答

为了能够让任何东西都得到“mousechange”处理,您可以添加一个CSS类:

mousechange:悬停{光标:指针;}<span class=“mousechange”>此处显示一些文本</span>

我不会说使用光标:指针,因为它只适用于InternetExplorer5.5及以下版本,而InternetExplorer6是随WindowsXP(2002)提供的。只有当浏览器停止工作时,人们才会得到升级的提示。此外,在Visual Studio中,它将在该条目下面加上红色下划线。它告诉我:

验证(CSS 3.0):“hand”不是“cursor”的有效值所有物

您可以使用以下代码:

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

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

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

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

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

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

.js li { cursor: pointer; }

您不需要jQuery,只需使用以下CSS内容:

li {cursor: pointer}

瞧!方便的

<style>
.para{
    color: black;
}
.para:hover{
    cursor: pointer;
    color: blue;
}
</style>
<div class="para">

在上面的HTML代码中,[:hover]用于指示以下样式只能应用于悬停或将鼠标光标保持在上面。

CSS中有几种类型的游标:

查看光标类型的以下代码:

<style>
.alias {cursor: alias;}
.all-scroll {cursor: all-scroll;}
.auto {cursor: auto;}
.cell {cursor: cell;}
.context-menu {cursor: context-menu;}
.col-resize {cursor: col-resize;}
.copy {cursor: copy;}
.crosshair {cursor: crosshair;}
.default {cursor: default;}
.e-resize {cursor: e-resize;}
.ew-resize {cursor: ew-resize;}
.grab {cursor: -webkit-grab; cursor: grab;}
.grabbing {cursor: -webkit-grabbing; cursor: grabbing;}
.help {cursor: help;}
.move {cursor: move;}
.n-resize {cursor: n-resize;}
.ne-resize {cursor: ne-resize;}
.nesw-resize {cursor: nesw-resize;}
.ns-resize {cursor: ns-resize;}
.nw-resize {cursor: nw-resize;}
.nwse-resize {cursor: nwse-resize;}
.no-drop {cursor: no-drop;}
.none {cursor: none;}
.not-allowed {cursor: not-allowed;}
.pointer {cursor: pointer;}
.progress {cursor: progress;}
.row-resize {cursor: row-resize;}
.s-resize {cursor: s-resize;}
.se-resize {cursor: se-resize;}
.sw-resize {cursor: sw-resize;}
.text {cursor: text;}
.url {cursor: url(myBall.cur),auto;}
.w-resize {cursor: w-resize;}
.wait {cursor: wait;}
.zoom-in {cursor: zoom-in;}
.zoom-out {cursor: zoom-out;}
</style>

单击以下链接以查看光标属性的操作方式:

https://www.w3schools.com/cssref/tryit.asp?filename=trycss_cursor