Skip to content

cursor

cursor 属性定义鼠标指针在元素上的显示样式。

语法

css
cursor: auto | default | none | context-menu | help | pointer | progress | wait | cell | crosshair | text | vertical-text | alias | copy | move | no-drop | not-allowed | grab | grabbing | all-scroll | col-resize | row-resize | n-resize | e-resize | s-resize | w-resize | ne-resize | nw-resize | se-resize | sw-resize | ew-resize | ns-resize | nesw-resize | nwse-resize | zoom-in | zoom-out | grab | grabbing | custom;

常见值

说明示例
auto自动cursor: auto
default默认cursor: default
nonecursor: 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
grab抓取cursor: grab
grabbing抓取中cursor: grabbing
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
ne-resize东北部调整cursor: ne-resize
nw-resize西北部调整cursor: nw-resize
se-resize东南部调整cursor: se-resize
sw-resize西南部调整cursor: sw-resize
ew-resize东西调整cursor: ew-resize
ns-resize南北调整cursor: ns-resize
nesw-resize东北-西南调整cursor: nesw-resize
nwse-resize西北-东南调整cursor: nwse-resize
zoom-in放大cursor: zoom-in
zoom-out缩小cursor: zoom-out

示例

基础用法

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;
}

/* 抓取 */
.grab {
  cursor: grab;
}

/* 抓取中 */
.grabbing {
  cursor: grabbing;
}

/* 全部滚动 */
.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;
}

/* 东北部调整 */
.ne-resize {
  cursor: ne-resize;
}

/* 西北部调整 */
.nw-resize {
  cursor: nw-resize;
}

/* 东南部调整 */
.se-resize {
  cursor: se-resize;
}

/* 西南部调整 */
.sw-resize {
  cursor: sw-resize;
}

/* 东西调整 */
.ew-resize {
  cursor: ew-resize;
}

/* 南北调整 */
.ns-resize {
  cursor: ns-resize;
}

/* 东北-西南调整 */
.nesw-resize {
  cursor: nesw-resize;
}

/* 西北-东南调整 */
.nwse-resize {
  cursor: nwse-resize;
}

/* 放大 */
.zoom-in {
  cursor: zoom-in;
}

/* 缩小 */
.zoom-out {
  cursor: zoom-out;
}

高级用法

css
/* 容器 */
.container {
  cursor: auto;
}

/* 静态 */
.static {
  cursor: auto;
}

/* 相对 */
.relative {
  cursor: auto;
}

/* 绝对 */
.absolute {
  cursor: auto;
}

/* 固定 */
.fixed {
  cursor: auto;
}

/* 粘性 */
.sticky {
  cursor: auto;
}

/* 响应式布局 */
.responsive {
  cursor: auto;
}

/* 卡片布局 */
.card {
  cursor: pointer;
}

/* 表单布局 */
.form {
  cursor: auto;
}

/* 图片画廊 */
.gallery {
  cursor: auto;
}

/* 混合单位 */
.mixed-units {
  cursor: auto;
}

/* 带命名的项目 */
.named-items {
  cursor: auto;
}

/* 悬停效果 */
.card {
  transition: cursor 0.3s ease-in-out;
}

.card:hover {
  cursor: pointer;
}

浏览器兼容性

浏览器版本
Chrome1+
Firefox1+
Safari1+
Edge12+
iOS Safari1+
Android Browser1+
Chrome for Android18+

注意事项

  • cursor 可以用于任何元素
  • cursor 定义鼠标指针在元素上的显示样式
  • auto 是默认值,表示自动

相关属性

相关资源