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

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

该文本描述了一个使用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>
复制全文 生成海报 前端开发 网页设计 用户体验

推荐文章

Vue3中如何进行性能优化?
2024-11-17 22:52:59 +0800 CST
什么是Vue实例(Vue Instance)?
2024-11-19 06:04:20 +0800 CST
回到上次阅读位置技术实践
2025-04-19 09:47:31 +0800 CST
7种Go语言生成唯一ID的实用方法
2024-11-19 05:22:50 +0800 CST
如何在 Linux 系统上安装字体
2025-02-27 09:23:03 +0800 CST
Vue3中的Slots有哪些变化?
2024-11-18 16:34:49 +0800 CST
JavaScript设计模式:单例模式
2024-11-18 10:57:41 +0800 CST
markdowns滚动事件
2024-11-19 10:07:32 +0800 CST
最全面的 `history` 命令指南
2024-11-18 21:32:45 +0800 CST
如何将TypeScript与Vue3结合使用
2024-11-19 01:47:20 +0800 CST
开源AI反混淆JS代码:HumanifyJS
2024-11-19 02:30:40 +0800 CST
mysql 计算附近的人
2024-11-18 13:51:11 +0800 CST
页面不存在404
2024-11-19 02:13:01 +0800 CST
Vue3中怎样处理组件引用?
2024-11-18 23:17:15 +0800 CST
jQuery `$.extend()` 用法总结
2024-11-19 02:12:45 +0800 CST
一些高质量的Mac软件资源网站
2024-11-19 08:16:01 +0800 CST
MyLib5,一个Python中非常有用的库
2024-11-18 12:50:13 +0800 CST
JavaScript设计模式:桥接模式
2024-11-18 19:03:40 +0800 CST
ElasticSearch 结构
2024-11-18 10:05:24 +0800 CST
一键压缩图片代码
2024-11-19 00:41:25 +0800 CST
PostgreSQL日常运维命令总结分享
2024-11-18 06:58:22 +0800 CST
用 Rust 玩转 Google Sheets API
2024-11-19 02:36:20 +0800 CST
Boost.Asio: 一个美轮美奂的C++库
2024-11-18 23:09:42 +0800 CST
JavaScript 上传文件的几种方式
2024-11-18 21:11:59 +0800 CST
robots.txt 的写法及用法
2024-11-19 01:44:21 +0800 CST
html文本加载动画
2024-11-19 06:24:21 +0800 CST
程序员茄子在线接单