Cursor 光标
在悬停在元素上时控制光标样式的实用工具。
| Class | Properties | Preview |
|---|
基本用法
设置光标样式
使用 cursor-{style} 来控制在悬停在元素上时显示哪个光标。
html
<button type="button" class="cursor-pointer ...">
Submit
</button>
<button type="button" class="cursor-progress ...">
Saving...
</button>
<button type="button" disabled class="cursor-not-allowed ...">
Confirm
</button>有条件地应用
悬停、焦点和其他状态
Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 focus:cursor-auto 只在悬停时应用 cursor-auto 实用程序。
html
<div class="cursor-not-allowed focus:cursor-auto">
<!-- ... -->
</div>有关所有可用状态修饰符的完整列表,请查看悬停、焦点和其他状态文档。
断点和媒体查询
您还可以使用变体修饰符来针对响应式断点、深色模式、偏好减少动作等媒体查询进行定位。例如,使用 md:cursor-auto 仅在中等屏幕尺寸及以上应用 cursor-auto 实用程序。
html
<div class="cursor-not-allowed md:cursor-auto">
<!-- ... -->
</div>要了解更多信息,请查看有关响应式设计、深色模式和其他媒体查询修饰符的文档。
使用自定义值
定制您的主题
默认情况下,Tailwind 包含了许多内置选项的 cursor 实用程序。您可以通过编辑 tailwind.config.js 文件中的 theme.cursor 或 theme.extend.cursor 来自定义这些值。
js
module.exports = {
theme: {
extend: {
cursor: {
'fancy': 'url(hand.cur), pointer',
}
}
}
}有关自定义默认主题的更多信息,请参阅主题自定义文档。
任意值
如果您需要使用一个与主题无关的 cursor 值,可以使用方括号来根据任意值动态生成属性。
html
<div class="cursor-[url(hand.cur),_pointer]">
<!-- ... -->
</div>有关任意值支持的更多信息,请参阅任意值文档。