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 格式。
  • 可以使用浏览器的开发者工具来快速测试和更改光标样式。
相关推荐
Sarvartha10 分钟前
三目运算符
linux·服务器·前端
晓晨的博客17 分钟前
ROS1录制的bag包转换为ROS2格式
前端·chrome
Wect25 分钟前
LeetCode 72. 编辑距离:动态规划经典题解
前端·算法·typescript
donecoding38 分钟前
别再让 pnpm 跟着 nvm 跑了!独立安装终极指南
前端·node.js·前端工程化
GISer_Jing40 分钟前
AI全栈转型_TS后端学习路线
前端·人工智能·后端·学习
竹林81841 分钟前
被The Graph的GraphQL查询坑了三天,我用一个真实DeFi项目把链上数据索引彻底搞懂了
前端·graphql
漫游的渔夫41 分钟前
前端开发者做 Agent:别只会执行,用 4 类失败策略让 AI 知道怎么停
前端·人工智能·typescript
用户0595401744644 分钟前
把多级缓存一致性验证从手工测试换成 Pytest 参数化,Bug 排查时间缩短 90%
前端·css
暗不需求1 小时前
深入理解 LangChain:AI 应用开发框架的工程化实践
前端·langchain
用户059540174461 小时前
把 Redis 持久化测试从 800 行 Shell 换成 30 行 pytest,排错效率翻了 10 倍
前端·css