竖向菜单栏-按钮切换与动画显示菜单项

 html

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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <header>
    <input type="checkbox" id="toggler">

    <label for="toggler">
      <span class="hambuger-container">
        <span></span>
        <span></span>
      </span>
    </label>

    <div class="nav-items">
      <ul>
        <li>Home</li>
        <li>iPhone</li>
        <li>iPad</li>
        <li>Mac</li>
        <li>TV</li>
      </ul>
    </div>
  </header>
</body>

</html>

css


#toggler {
  display: none;
}

.hambuger-container {
  display: block;
  width: 20px;
  height: 20px;
  position: relative;
  top: 18px;
}

.hambuger-container span {
  display: block;
  height: 1px;
  background-color: #fff;
  position: relative;
  transition: transform .3s ease-in-out, top .3s ease-in-out .3s;
  top: 0;
}

.hambuger-container span:nth-child(2) {
  margin-top: 7px;
}

#toggler:checked + label .hambuger-container span:nth-child(1) {
  transform: rotate(45deg);
  top: 4px;
  transition: top .3s ease-in-out, transform .3s ease-in-out .3s;
}

#toggler:checked + label .hambuger-container span:nth-child(2) {
  transform: rotate(-45deg);
  top: -4px;
  transition: top .3s ease-in-out, transform .3s ease-in-out .3s;
}

header {
  height: 44px;
  background-color: #000;
  padding: 0 18px;
}

body {
  padding: 0;
  margin: 0;
}

.nav-items {
  background-color: rgba(0, 0, 0, .82);
  width: 100%;
  height: 100vh;
  position: absolute;
  top: 44px;
  left: 0;
  transform: scaleY(0);
  transition: all .4s ease-in-out;
  transform-origin: 50% 0;
  /* opacity: 0; */
}

#toggler:checked ~ .nav-items {
  
  transform: scaleY(1);
  /* opacity: 1; */
}

ul {
  margin-top: 1em;
}

ul li {
  color: #fff;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值