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

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

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


当前回答

只需输入此代码。

li{cursor: pointer;}

其他回答

您可以使用以下代码:

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

只需使用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

<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

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

li {cursor: pointer}

瞧!方便的

您可以使用以下选项之一:

li:hover
{
 cursor: pointer;
}

or

li
{
 cursor: pointer;
}

工作示例1:

li:悬停{光标:指针;}<ul><li>食品</li><li>巴</li></ul>

工作示例2:

锂{光标:指针;}<ul><li>食品</li><li>巴</li></ul>