要使鼠标悬浮在按钮上时变成手指形状(表示这是一个可点击的区域),可以使用 CSS 的 cursor
属性来实现。
css复制代码.button { cursor: pointer; /* 鼠标悬浮时显示手指形状 */}
html复制代码<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>悬浮变手指示例</title> <link rel="stylesheet" href="styles.css"></head><body> <button class="button">点击我</button></body></html>
css复制代码/* styles.css */.button { padding: 10px 20px; font-size: 16px; background-color: #3498db; color: white; border: none; border-radius: 5px; cursor: pointer; /* 鼠标悬浮时显示手指形状 */ transition: background-color 0.3s; }.button:hover { background-color: #2980b9; /* 鼠标悬浮时按钮变暗 */}
cursor: pointer;
:设置鼠标悬浮在元素上时,光标变为手指形状,表示该元素是可点击的。
.button:hover
:使用伪类 :hover
来设置鼠标悬浮效果,这里使背景色变暗,进一步增强了用户的交互体验。
当鼠标悬浮在按钮上时,光标会变成手指形状,同时按钮的背景色会变暗,提示用户该按钮是可以点击的。