css鼠标常用样式

在CSS中,你可以通过**cursor**属性来改变鼠标指针的样式。这个属性可以应用于任何HTML元素上,使得当鼠标悬停在该元素上时,鼠标指针会呈现出不同的样式。这对于提高用户体验和网页的互动性非常有帮助。

以下是一些常见的鼠标样式和用法示例:

  1. 默认样式

    复制代码
    .default { cursor: default; /* 默认光标 */ }
  2. 指针样式

    复制代码
    .pointer { cursor: pointer; /* 手形光标,用于可点击元素 */ }
  3. 文本选择样式

    复制代码
    .text { cursor: text; /* 文本选择光标 */ }
  4. 等待样式

    复制代码
    .wait { cursor: wait; /* 等待光标,通常用于加载状态 */ }
  5. 自定义光标: 你也可以使用自定义图像作为光标:

    复制代码
    .custom { cursor: url('path/to/cursor.png'), auto; /* 指定自定义光标 */ }
  6. 禁用样式

    复制代码
    .not-allowed { cursor: not-allowed; /* 禁止光标 */ }

示例

以下是一个简单的示例,展示如何在不同元素上应用不同的鼠标样式:

复制代码
<div class="default">这是默认光标</div>
<div class="pointer">这是指针光标</div>
<div class="text">这是文本光标</div>
<div class="wait">这是等待光标</div>
<div class="custom">这是自定义光标</div>
<div class="not-allowed">这是禁止光标</div>

div {
    padding: 20px;
    margin: 10px;
    border: 1px solid #ccc;
}

.pointer {
    cursor: pointer;
}

.text {
    cursor: text;
}

.wait {
    cursor: wait;
}

.custom {
    cursor: url('path/to/cursor.png'), auto;
}

.not-allowed {
    cursor: not-allowed;
}

小提示

  • 自定义光标的图像通常建议使用小于 32x32 像素的 PNG 或 SVG 格式。
  • 可以使用浏览器的开发者工具来快速测试和更改光标样式。
相关推荐
GISer_Jing14 小时前
Agent技术深度解析:LLM增强智能体架构与优化
前端·人工智能·架构·aigc
難釋懷14 小时前
Redis主从-主从数据同步原理
前端·数据库·redis
a11177614 小时前
Markdown生成思维导图(html 开源)
前端·开源·html
我命由我1234515 小时前
React - state、state 的简写方式、props、props 的简写方式、类式组件中的构造器与 props、函数式组件使用 props
前端·javascript·react.js·前端框架·html·html5·js
钰衡大师15 小时前
Vue 3 源码学习教程
前端·vue.js·学习
C澒15 小时前
React + TypeScript 编码规范|统一标准 & 高效维护
前端·react.js·typescript·团队开发·代码规范
时光少年15 小时前
Android 视频分屏性能优化——GLContext共享
前端
风无雨15 小时前
滚动条上下按钮隐藏不生效的原因与修复(::-webkit-scrollbar-button)
css·css3·webkit
IT_陈寒15 小时前
JavaScript开发者必知的5个性能杀手,你踩了几个坑?
前端·人工智能·后端
跟着珅聪学java15 小时前
Electron 精美菜单设计
运维·前端·数据库