HTML&CSS:这个动态删除按钮打几分?

这段HTML和CSS代码创建了一个可交互的按钮,该按钮在鼠标悬停时会展开显示一个删除图标和文字标签

演示效果

HTML&CSS

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>前端Hardy</title>
    <style>
        body {
            background: #e8e8e8;
            padding: 0;
            margin: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        .button {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: rgb(20, 20, 20);
            border: none;
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.164);
            cursor: pointer;
            transition-duration: .3s;
            overflow: hidden;
            position: relative;
        }

        .svgIcon {
            width: 12px;
            transition-duration: .3s;
        }

        .svgIcon path {
            fill: white;
        }

        .button:hover {
            width: 140px;
            border-radius: 50px;
            transition-duration: .3s;
            background-color: rgb(255, 69, 69);
            align-items: center;
        }

        .button:hover .svgIcon {
            width: 50px;
            transition-duration: .3s;
            transform: translateY(60%);
        }

        .button::before {
            position: absolute;
            top: -20px;
            content: "Delete";
            color: white;
            transition-duration: .3s;
            font-size: 2px;
        }

        .button:hover::before {
            font-size: 13px;
            opacity: 1;
            transform: translateY(30px);
            transition-duration: .3s;
        }
    </style>
</head>

<body>
    <button class="button">
        <svg viewBox="0 0 448 512" class="svgIcon">
            <path
                d="M135.2 17.7L128 32H32C14.3 32 0 46.3 0 64S14.3 96 32 96H416c17.7 0 32-14.3 32-32s-14.3-32-32-32H320l-7.2-14.3C307.4 6.8 296.3 0 284.2 0H163.8c-12.1 0-23.2 6.8-28.6 17.7zM416 128H32L53.2 467c1.6 25.3 22.6 45 47.9 45H346.9c25.3 0 46.3-19.7 47.9-45L416 128z">
            </path>
        </svg>
    </button>
</body>
</html>

HTML结构

  • button:这是一个按钮元素,用于触发点击事件。
  • svgIcon:这是一个SVG图标,用于在按钮中显示一个图标。viewBox属性定义了SVG画布的尺寸和位置,class="svgIcon"用于应用SVG相关的样式。

CSS样式

  • .button:定义了按钮的基本样式,包括尺寸、边框半径、背景颜色、边框、字体权重、显示方式、对齐方式、盒子阴影、光标样式、过渡效果、溢出隐藏和定位。
  • .svgIcon:定义了SVG图标的基本样式,包括宽度和过渡效果。
  • .svgIcon path:定义了SVG图标路径的填充颜色。
  • .button:hover:定义了鼠标悬停在按钮上时的样式,包括宽度、边框半径、背景颜色、对齐方式和过渡效果。
  • .button:hover .svgIcon:定义了鼠标悬停在按钮上时SVG图标的样式,包括宽度、过渡效果和Y轴变换。
  • .button::before:使用了伪元素::before来在按钮上添加一个隐藏的文本标签,包括位置、内容、颜色、过渡效果和字体大小。
  • .button:hover::before:定义了鼠标悬停在按钮上时伪元素::before的样式,包括字体大小、透明度、Y轴变换和过渡效果。
相关推荐
paopaokaka_luck39 分钟前
基于SpringBoot+Uniapp的健身饮食小程序(协同过滤算法、地图组件)
前端·javascript·vue.js·spring boot·后端·小程序·uni-app
患得患失9491 小时前
【前端】【vscode】【.vscode/settings.json】为单个项目配置自动格式化和开发环境
前端·vscode·json
飛_1 小时前
解决VSCode无法加载Json架构问题
java·服务器·前端
YGY Webgis糕手之路4 小时前
OpenLayers 综合案例-轨迹回放
前端·经验分享·笔记·vue·web
90后的晨仔4 小时前
🚨XSS 攻击全解:什么是跨站脚本攻击?前端如何防御?
前端·vue.js
Ares-Wang4 小时前
JavaScript》》JS》 Var、Let、Const 大总结
开发语言·前端·javascript
90后的晨仔4 小时前
Vue 模板语法完全指南:从插值表达式到动态指令,彻底搞懂 Vue 模板语言
前端·vue.js
德育处主任5 小时前
p5.js 正方形square的基础用法
前端·数据可视化·canvas
烛阴5 小时前
Mix - Bilinear Interpolation
前端·webgl
90后的晨仔5 小时前
Vue 3 应用实例详解:从 createApp 到 mount,你真正掌握了吗?
前端·vue.js