Css 当用户将光标悬停在列表项上时,如何将光标变为手形?

Css 当用户将光标悬停在列表项上时,如何将光标变为手形?,css,Css,我有一个列表,它的项目有一个点击处理程序: <ul> <li>foo</li> <li>goo</li> </ul> 福 黏液 如何将鼠标指针更改为手动指针(如将鼠标悬停在按钮上)?现在,当我将鼠标悬停在列表项上时,指针将变成文本选择指针。您不需要jQuery,只需使用以下CSS内容即可: li {cursor: pointer} 瞧!方便。随着时间的推移,正如人们所提到的,您现在可以安全地使用: li{光

我有一个列表,它的项目有一个点击处理程序:

<ul>
  <li>foo</li>
  <li>goo</li>
</ul>
  • 黏液

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

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

li {cursor: pointer}

瞧!方便。

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

li{光标:指针;}
使用


如果你想得到一个交叉浏览器的结果

对于完整的跨浏览器,请使用:

cursor: pointer;
cursor: hand;
使用:


可以查看当前HTML规范的其他有效值(即
hand
不是)。

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

要实现这一点,可以使用JavaScript库jQuery将CSS添加到元素中,如下所示

$("li").css({"cursor":"pointer"});
或者将其直接链接到单击处理程序

或者与
结合使用时,CSS将如下所示:

.js li { cursor: pointer; }
li { 
  cursor: pointer;
}

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

.mousechange:悬停{
光标:指针;
}
此处的一些文本
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;
}

对于基本的手形符号:

试一试

如果需要手形符号,如拖放某个项目,请尝试:

cursor: grab
使用:


有关更多鼠标事件,请选中。

所有其他响应都建议使用标准CSS指针,但是,有两种方法:

  • 应用CSS属性
    光标:指针到元素。(这是光标悬停在按钮上时的默认样式。)

  • 应用CSS属性
    cursor:url(pointer.png)为指针使用自定义图形。如果您希望确保用户体验在所有平台上都是相同的(而不是让浏览器/操作系统决定指针光标的外观),那么这可能更可取。请注意,如果找不到图像,可以添加回退选项,包括辅助url或任何其他选项,即
    cursor:url(pointer.png,fallback.png,pointer)

  • 当然,这些可以通过以下方式应用于列表项:
    li{cursor:pointer;}
    ,作为类
    .class{cursor:pointer;}
    ,或者作为每个元素的style属性的值
    style=“cursor:pointer;”
    注意:不建议这样做,因为这被认为是不好的做法

    将内容包装在包含
    href
    属性的锚定标记中,无需显式应用
    光标:指针具有锚属性副作用的属性(用CSS修订):

    仅为完整起见:

    cursor: -webkit-grab;
    
    它还提供了一只手,在移动图像视图时您知道的手

    如果您想使用jQuery和mousedown,它非常有用


    用于
    li

    li:hover {
        cursor: pointer;
    }
    
    运行代码段选项后查看更多光标属性及示例:

    .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{光标:crosshair;}
    .text{cursor:text;}
    .vertical text{光标:vertical text;}
    .alias{cursor:alias;}
    .copy{cursor:copy;}
    .move{cursor:move;}
    .no drop{光标:no drop;}
    .不允许{游标:不允许;}
    .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;}
    .cursors>div{
    浮动:左;
    框大小:边框框;
    背景#f2f2;
    边框:1px实心#ccc;
    宽度:20%;
    填充:10px 2px;
    文本对齐:居中;
    空白:nowrap;
    &:第n个孩子(偶数){
    背景:#eee;
    }
    &:悬停{
    不透明度:0.25
    }
    }
    光标示例
    汽车
    违约
    没有一个
    上下文菜单
    帮助
    指针
    进步
    等待
    细胞
    十字线
    文本
    垂直文本
    别名
    复制
    移动
    不滴
    不准
    全部卷轴
    列大小调整
    行大小调整
    向北的箭头
    向下箭头
    向东的箭头
    向西的箭头
    ns调整大小
    ew调整大小
    箭头朝右上
    指向西北的箭头
    向东南的箭头
    左下箭头
    nesw调整大小
    nwse调整大小
    
    只需执行以下操作:

    .js li { cursor: pointer; }
    
    li { 
      cursor: pointer;
    }
    
    我将其应用于您的代码,以了解其工作原理:

    li{
    光标:指针;
    }
    • 黏液

    您也可以使用以下样式:

    li {
        cursor: grabbing;
    }
    

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

    li:hover
    {
     cursor: pointer;
    }
    

    工作示例1:

    li:悬停
    {
    光标:指针;
    }
    • 酒吧

    您可以使用以下代码:


    li:hover{cursor:pointer;}
    检查以下内容。我从你那里得到的

    .alias{cursor:alias;}
    .all scroll{cursor:all scroll;}
    .auto{cursor:auto;}
    .cell{cursor:cell;}
    .上下文菜单{光标:c
    
    li:hover {
        cursor: pointer;
    }
    
    li { 
      cursor: pointer;
    }
    
    li {
        cursor: grabbing;
    }
    
    li:hover
    {
     cursor: pointer;
    }
    
    li
    {
     cursor: pointer;
    }
    
    <style>
    .para{
        color: black;
    }
    .para:hover{
        cursor: pointer;
        color: blue;
    }
    </style>
    <div class="para">
    
    <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>