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

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

该文本描述了一个使用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-18 10:15:48 +0800 CST
deepcopy一个Go语言的深拷贝工具库
2024-11-18 18:17:40 +0800 CST
Go 单元测试
2024-11-18 19:21:56 +0800 CST
Java环境中使用Elasticsearch
2024-11-18 22:46:32 +0800 CST
PHP服务器直传阿里云OSS
2024-11-18 19:04:44 +0800 CST
聚合支付管理系统
2025-07-23 13:33:30 +0800 CST
thinkphp分页扩展
2024-11-18 10:18:09 +0800 CST
Vue中的表单处理有哪几种方式?
2024-11-18 01:32:42 +0800 CST
支付页面html收银台
2025-03-06 14:59:20 +0800 CST
Go语言中的`Ring`循环链表结构
2024-11-19 00:00:46 +0800 CST
filecmp,一个Python中非常有用的库
2024-11-19 03:23:11 +0800 CST
动态渐变背景
2024-11-19 01:49:50 +0800 CST
前端开发中常用的设计模式
2024-11-19 07:38:07 +0800 CST
18个实用的 JavaScript 函数
2024-11-17 18:10:35 +0800 CST
使用Vue 3实现无刷新数据加载
2024-11-18 17:48:20 +0800 CST
程序员茄子在线接单