android 汉堡菜单动画,纯CSS实现的汉堡菜单折叠展开动画

这篇博客详细介绍了如何使用CSS语言创建一个汉堡菜单,并实现菜单展开和关闭的平滑过渡动画。通过设置不同的样式和转换规则,使得 burger 类选择器在 burger-check 检查状态改变时,能够触发导航栏的最大高度变化,实现导航栏的显示和隐藏。此外,还展示了如何利用伪元素before和after来创建汉堡菜单的线条动画效果。
摘要由CSDN通过智能技术生成

CSS

语言:

CSSSCSS

确定

.burger {

display: inline-block;

border: 0;

background: none;

outline: 0;

padding: 0;

cursor: pointer;

border-bottom: 4px solid currentColor;

width: 28px;

transition: border-bottom 1s ease-in-out;

-webkit-transition: border-bottom 1s ease-in-out;

}

.burger::-moz-focus-inner {

border: 0;

padding: 0;

}

.burger:before {

content: "";

display: block;

border-bottom: 4px solid currentColor;

width: 100%;

margin-bottom: 5px;

transition: transform 0.5s ease-in-out;

-webkit-transition: -webkit-transform 0.5s ease-in-out;

}

.burger:after {

content: "";

display: block;

border-bottom: 4px solid currentColor;

width: 100%;

margin-bottom: 5px;

transition: transform 0.5s ease-in-out;

-webkit-transition: -webkit-transform 0.5s ease-in-out;

}

.burger-check {

display: none;

}

.burger-check:checked ~ .burger {

border-bottom: 4px solid transparent;

transition: border-bottom 0.8s ease-in-out;

-webkit-transition: border-bottom 0.8s ease-in-out;

}

.burger-check:checked ~ .burger:before {

-ms-transform: rotate(-405deg) translateY(1px) translateX(-3px);

transform: rotate(-405deg) translateY(1px) translateX(-3px);

-webkit-transform: rotate(-405deg) translateY(1px) translateX(-3px);

transition: transform 0.5s ease-in-out;

-webkit-transition: -webkit-transform 0.5s ease-in-out;

}

.burger-check:checked ~ .burger:after {

-ms-transform: rotate(405deg) translateY(-4px) translateX(-5px);

transform: rotate(405deg) translateY(-4px) translateX(-5px);

-webkit-transform: rotate(405deg) translateY(-4px) translateX(-5px);

transition: transform 0.5s ease-in-out;

-webkit-transition: -webkit-transform 0.5s ease-in-out;

}

.navigation {

overflow: hidden;

max-height: 0;

-webkit-transition: max-height 0.5s ease-in-out;

transition: max-height 0.5s ease-in-out;

}

.burger-check:checked ~ .navigation {

max-height: 500px;

-webkit-transition: max-height 0.5s ease-in-out;

transition: max-height 0.5s ease-in-out;

}

body {

background-color: floralwhite;

font-family: 'Libre Baskerville', serif;

font-style: italic;

font-size: 30px;

text-align: centeR;

}

a {

color: inherit;

}

small {

font-size: 14px;

}

ul {

margin: 0;

padding: 0;

}

li {

list-style: none;

font-size: 25px;

padding: 5px 0;

}

li a {

text-decoration: none;

}

li a:hover {

text-decoration: underline;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值