客户至上 · 专业至上
Customer first and professional first

鼠标悬浮到按钮变成手指的css怎么写

来源:沐阳科技 作者:网页制作 2024-09-03 16:46:57 0

要使鼠标悬浮在按钮上时变成手指形状(表示这是一个可点击的区域),可以使用 CSS 的 cursor 属性来实现。

CSS 示例

css复制代码.button {    cursor: pointer; /* 鼠标悬浮时显示手指形状 */}

应用示例

HTML 结构

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 样式

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 来设置鼠标悬浮效果,这里使背景色变暗,进一步增强了用户的交互体验。

效果

当鼠标悬浮在按钮上时,光标会变成手指形状,同时按钮的背景色会变暗,提示用户该按钮是可以点击的。