代码 HTML和CSS创建的弹性菜单

2024-11-19 10:09:04 +0800 CST views 771

该文本描述了一个使用HTML和CSS创建的弹性菜单。菜单包含四个项目:主页、关于、服务和联系。通过CSS样式和动画效果,菜单项在悬停时会改变颜色并产生弹跳效果,增强用户体验。代码中使用了flex布局和关键帧动画,使菜单在视觉上更加吸引人。

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>弹性菜单</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }

        .menu {
            list-style-type: none;
            padding: 0;
            display: flex;
            background-color: #ffffff;
            border-radius: 8px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        }

        .menu-item {
            margin: 0;
            padding: 15px 25px;
            font-size: 18px;
            color: #333;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .menu-item::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            width: 0;
            height: 3px;
            background-color: #3498db;
            transition: all 0.3s ease;
        }

        .menu-item:hover {
            color: #3498db;
            transform: translateY(-3px);
            animation: elasticBounce 0.5s ease;
        }

        .menu-item:hover::after {
            width: 100%;
            left: 0;
        }

        @keyframes elasticBounce {
            0% {
                transform: translateY(-3px) scale(1);
            }

            25% {
                transform: translateY(-3px) scale(1.1);
            }

            50% {
                transform: translateY(-3px) scale(0.9);
            }

            75% {
                transform: translateY(-3px) scale(1.05);
            }

            100% {
                transform: translateY(-3px) scale(1);
            }
        }

        .menu-item::before {
            content: '';
            position: absolute;
            top: 0;
            left: 50%;
            width: 0;
            height: 100%;
            background-color: rgba(52, 152, 219, 0.1);
            transform: skew(-20deg);
            transition: all 0.4s ease;
            z-index: -1;
        }

        .menu-item:hover::before {
            width: 150%;
            left: -25%;
        }
    </style>
</head>

<body>
    <ul class="menu">
        <li class="menu-item">Home</li>
        <li class="menu-item">About</li>
        <li class="menu-item">Services</li>
        <li class="menu-item">Contact</li>
    </ul>
</body>

</html>
复制全文 生成海报 前端开发 网页设计 用户体验

推荐文章

55个常用的JavaScript代码段
2024-11-18 22:38:45 +0800 CST
pip安装到指定目录上
2024-11-17 16:17:25 +0800 CST
Vue3中的Scoped Slots有什么改变?
2024-11-17 13:50:01 +0800 CST
Vue3中的v-slot指令有什么改变?
2024-11-18 07:32:50 +0800 CST
php内置函数除法取整和取余数
2024-11-19 10:11:51 +0800 CST
windon安装beego框架记录
2024-11-19 09:55:33 +0800 CST
html一些比较人使用的技巧和代码
2024-11-17 05:05:01 +0800 CST
JavaScript设计模式:组合模式
2024-11-18 11:14:46 +0800 CST
防止 macOS 生成 .DS_Store 文件
2024-11-19 07:39:27 +0800 CST
阿里云免sdk发送短信代码
2025-01-01 12:22:14 +0800 CST
Rust 中的所有权机制
2024-11-18 20:54:50 +0800 CST
MyLib5,一个Python中非常有用的库
2024-11-18 12:50:13 +0800 CST
Vue中的`key`属性有什么作用?
2024-11-17 11:49:45 +0800 CST
纯CSS实现3D云动画效果
2024-11-18 18:48:05 +0800 CST
设置mysql支持emoji表情
2024-11-17 04:59:45 +0800 CST
html流光登陆页面
2024-11-18 15:36:18 +0800 CST
Vue3 组件间通信的多种方式
2024-11-19 02:57:47 +0800 CST
mysql关于在使用中的解决方法
2024-11-18 10:18:16 +0800 CST
H5抖音商城小黄车购物系统
2024-11-19 08:04:29 +0800 CST
【SQL注入】关于GORM的SQL注入问题
2024-11-19 06:54:57 +0800 CST
Rust开发笔记 | Rust的交互式Shell
2024-11-18 19:55:44 +0800 CST
JavaScript 流程控制
2024-11-19 05:14:38 +0800 CST
Golang中国地址生成扩展包
2024-11-19 06:01:16 +0800 CST
FastAPI 入门指南
2024-11-19 08:51:54 +0800 CST
程序员茄子在线接单