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 格式。
  • 可以使用浏览器的开发者工具来快速测试和更改光标样式。
相关推荐
麒麟而非淇淋几秒前
AJAX 入门 day3
前端·javascript·ajax
茶茶只知道学习13 分钟前
通过鼠标移动来调整两个盒子的宽度(响应式)
前端·javascript·css
蒟蒻的贤16 分钟前
Web APIs 第二天
开发语言·前端·javascript
清灵xmf19 分钟前
揭开 Vue 3 中大量使用 ref 的隐藏危机
前端·javascript·vue.js·ref
蘑菇头爱平底锅21 分钟前
十万条数据渲染到页面上如何优化
前端·javascript·面试
su1ka11125 分钟前
re题(35)BUUCTF-[FlareOn4]IgniteMe
前端
测试界柠檬26 分钟前
面试真题 | web自动化关闭浏览器,quit()和close()的区别
前端·自动化测试·软件测试·功能测试·程序人生·面试·自动化
多多*27 分钟前
OJ在线评测系统 登录页面开发 前端后端联调实现全栈开发
linux·服务器·前端·ubuntu·docker·前端框架
2301_8010741528 分钟前
TypeScript异常处理
前端·javascript·typescript
小阿飞_29 分钟前
报错合计-1
前端