CSSだけで作るハンバーガーメニュー


![スクリーンショット 2022-09-13 171705.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/515025/64f564af-acc5-7098-2811-ba3e31a095c5.png)
![スクリーンショット 2022-09-13 171634.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/515025/4d5cb076-a725-ac5b-7969-d2a39d0af389.png)


```html

    <header class="header">

        <input type="checkbox" class="menu-btn" id="menu-btn">
        <label for="menu-btn" class="menu-icon"><span class="navicon"></span></label>
        <ul class="menu">
            <li><a href="#1">1</a></li>
            <li><a href="#2">2</a></li>
            <li><a href="#3">3</a></li>
        </ul>

    </header>

```


```css
        .header {
            background: var(--background-navbar);
            position: fixed;
            width: 100%;
            height: 52px;
            z-index: 1;
            text-align: right;
        }

        /* Nav items */
        .menu {
            list-style: none;
            position: absolute;
            width: 100%;
            height: auto;
            top: 0;
            margin-top: 52px;
            padding: 0 0 10px 0;
            clear: both;
            background: var(--background-navbar);
            transition: 0.3192s cubic-bezier(0.04, 0.04, 0.12, 0.96) 0.1008s;
            transform: scale(1, 0);
            transform-origin: top;
        }

        /* Hamburger menu button */
        .menu-btn:checked~.menu {
            transform: scale(1, 1);
            transform-origin: top;
            transition: 0.3192s cubic-bezier(0.04, 0.04, 0.12, 0.96) 0.1008s;
        }

        /* Hamburger menbu text */
        .menu a {
            text-decoration: none;
            font-weight: 500;
            font-size: 15px;
            color: black;
            opacity: 0;
            transition: 0.5s;
        }

        .menu li {
            margin-left: auto;
            opacity: 0;
            transition: 0.5s;
            width: 26%;
        }

        .menu-btn:checked~.menu a,
        .menu-btn:checked~.menu li {
            opacity: 1;
            transition: 0.3192s cubic-bezier(0.04, 0.04, 0.12, 0.96) 0.2s;
            padding: 1%;
        }

        .menu-btn:checked~.menu li {
            background-color: rgba(255, 255, 255, 0.6);
        }

        .menu-btn {
            display: none;
        }

        .menu-icon {
            display: inline-block;
            position: relative;
            cursor: pointer;
            padding: 24px 14px;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
        }

        .navicon {
            background: black;
            display: block;
            height: 3px;
            width: 26px;
            position: relative;
            transition: 0.3192s cubic-bezier(0.04, 0.04, 0.12, 0.96) 0.1008s;
        }

        .navicon:before,
        .navicon:after {
            content: "";
            display: block;
            height: 100%;
            width: 100%;
            position: absolute;
            background: black;
            transition: 0.3192s cubic-bezier(0.04, 0.04, 0.12, 0.96) 0.1008s;
        }

        .navicon:before {
            top: 9px;
        }

        .navicon:after {
            bottom: 9px;
        }

        /* Hamburger Menu Animation Start */
        .menu-btn:checked~.menu-icon .navicon:before {
            transform: rotate(-45deg);
        }

        .menu-btn:checked~.menu-icon .navicon:after {
            transform: rotate(45deg);
        }

        .menu-btn:checked~.menu-icon:not(.steps) .navicon:before {
            top: 0;
        }

        .menu-btn:checked~.menu-icon:not(.steps) .navicon:after {
            bottom: 0;
        }

        .menu-btn:checked~.menu-icon .navicon {
            background: rgba(0, 0, 0, 0);
            transition: 0.2192s cubic-bezier(0.04, 0.04, 0.12, 0.96) 0.1008s;
        }

        /* Hamburger Menu Animation End */

        @media screen and (max-width: 767px),
        print {
            .menu a {
                font-size: 10px;
            }
        }

```