CSS3手风琴效果

本文介绍了一种使用HTML和CSS实现的垂直手风琴菜单样式。通过巧妙地利用CSS渐变、过渡和伪元素等特性,实现了手风琴菜单的动态展开与收起效果。该菜单具有良好的交互体验,并且可以通过简单的链接点击来切换不同部分的内容。
摘要由CSDN通过智能技术生成
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title> 垂直手风琴</title>
    <style type="text/css">
        .accordionMenu {
            background: #fff;
            color: #424242;
            font: 12px Arial, Verdana, sans-serif;
            margin: 0 auto;
            padding: 10px;
            width: 500px;
        }

        .accordionMenu h2 {
            margin: 5px 0;
            padding: 0;
            position: relative;
        }

        .accordionMenu h2:before {
            /* 制作向下三角效果*/
            border: 5px solid #fff;
            border-color: #fff transparent transparent;
            content: "";
            height: 0;
            position: absolute;
            right: 10px;
            top: 15px;
            width: 0;
        }

        .accordionMenu h2 a {
            /* 制作手风琴标题栏效果*/
            background: #8f8f8f;
            background: -moz-linear-gradient(top, #cecece, #8f8f8f);
            background: -webkit-gradient(linear, left top, left bottom,
            from(#cecece), to(#8f8f8f));
            background: -webkit-linear-gradient(top, #cecece, #8f8f8f);
            background: -o-linear-gradient(top, #cecece, #8f8f8f);
            background: linear-gradient(top, #cecece, #8f8f8f);
            border-radius: 5px;
            color: #424242;
            display: block;
            font-size: 13px;
            font-weight: normal;
            margin: 0;
            padding: 10px 10px;
            text-shadow: 2px 2px 2px #aeaeae;
            text-decoration: none;
        }

        .accordionMenu :target h2 a, /* 目标标题的效果*/
        .accordionMenu h2 a:focus,
        .accordionMenu h2 a:hover,
        .accordionMenu h2 a:active {
            background: #2288dd;
            background: -moz-linear-gradient(top, #6bb2ff, #2288dd);
            background: -webkit-gradient(linear, left top, left bottom,
            from(#6bb2ff), to(#2288dd));
            background: -webkit-linear-gradient(top, #6bb2ff, #2288dd);
            background: -o-linear-gradient(top, #6bb2ff, #2288dd);
            background: linear-gradient(top, #6bb2ff, #2288dd);
            color: #FFF;
        }

        .accordionMenu p {
            /* 标题栏对应的内容*/
            margin: 0;
            height: 0; /* 默认栏目内容高度为0,达到隐藏效果*/
            overflow: hidden;
            padding: 0 10px;
            -moz-transition: height 0.5s ease-in;
            -webkit-transition: height 0.5s ease-in;
            -o-transition: height 0.5s ease-in;
            transition: height 0.5s ease-in;
        }

        /* 这部分是显示内容的关键代码*/
        .accordionMenu :target p {
            /* 展开对应目标内容*/
            height: 100px; /* 显示对应目标栏内容*/
            overflow: auto;
        }

        .accordionMenu :target h2:before {
            /* 展开时标题三角效果*/
            border-color: transparent transparent transparent #fff;
        }
    </style>
</head>
<body>
<div class="accordionMenu">
    <div class="menuSection" id="brand">
        <h2><a href="#brand">Brand</a></h2>

        <p>Lorem ipsum dolor...</p>
    </div>
    <div class="menuSection" id="promotion">
        <h2><a href="#promotion">Promotion</a></h2>

        <p>Lorem ipsum dolor sit amet...</p>
    </div>
    <div class="menuSection" id="event">
        <h2><a href="#event">Event</a></h2>

        <p>Lorem ipsum dolor sit amet...</p>
    </div>
</div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值