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

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

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


当前回答

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

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>

<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

检查以下内容。我从W3Schools得到。

.alias{游标:别名;}.all scroll{cursor:all scroll;}.auto{cursor:auto;}.cell{光标:单元格;}.上下文菜单{光标:上下文菜单;}.col resize{cursor:col resize;}.copy{cursor:copy;}.croshair{cursor:croshair;}.default{cursor:默认;}.e-resize{cursor:e-size;}.ew resize{cursor:ew resize;}.抓取{光标:-webkit抓取;光标:抓取;}.抓取{光标:-webkit抓取;光标:抓取;}.help{光标:帮助;}.move{光标:移动;}.n-resize{cursor:n-resize;}.ne resize{cursor:ne resize;}.new resize{cursor:new resize;}.ns resize{cursor:ns resize;}.nw resize{cursor:nw resize;}.nwse resize{光标:nwse resize;}.no drop{游标:no drop;}.none{cursor:none;}.不允许{游标:不允许;}.pointer{cursor:pointer;}.进度{光标:进度;}.row resize{cursor:行大小调整;}.s-resize{cursor:s-resize;}.se resize{cursor:se resize;}.sw resize{cursor:sw resize;}.text{cursor:text;}.url{cursor:url(myBall.cur),自动;}.w-resize{cursor:w-resize;}.wait{游标:等待;}.放大{光标:放大;}.缩小{光标:缩小;}<!DOCTYPE html><html><body><h1>游标属性</h1><p>将鼠标悬停在单词上以更改鼠标光标</p>别名</p><p class=“all scroll”>全部滚动</p><p class=“auto”>自动</p><p class=“cell”>单元格</p><p class=“context menu”>上下文菜单</p><p class=“col resize”>col resze</p><p class=“copy”>复制</p>十字准线</p><p class=“default”>默认值</p><p class=“e-size”>e-size</p><p class=“ew resize”>ew resize</p><p class=“grab”>抓取</p><p class=“抓取”>抓取</p><p class=“help”>帮助</p><p class=“move”>移动</p><p class=“n-resize”>n-resize</p><p class=“ne resize”>ne resize</p><p class=“nesw resize”>nesw resze</p><p class=“ns resize”>ns resize</p><p class=“nw-resize”>nw-resize</p><p class=“nwse resize”>nwse resze</p><p class=“no drop”>不掉落</p><p class=“none”>无</p><p class=“not allowed”>不允许</p><p class=“pointer”>指针</p><p class=“progress”>进度</p><p class=“row resize”>调整行大小</p><p class=“s-resize”>s-resize</p><p class=“se resize”>se resize</p><p class=“sw-resize”>sw-resize</p><p class=“text”>text</p><p class=“url”>url</p><p class=“w-resize”>w-resize</p><p class=“wait”>等待</p><p class=“zoom in”>放大</p><p class=“zoom out”>缩小</p></body></html>

您可以在悬停时更改它,也可以只在列表项上指定光标:指针,两者都可以。

ul li {
  cursor: pointer;
}

或者

ul li:hover {
  cursor: pointer;
}

仅为完整起见:

cursor: -webkit-grab;

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

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