0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

Last updated at Posted at 2022-09-13

スクリーンショット 2022-09-13 171705.png
スクリーンショット 2022-09-13 171634.png


    <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>

        .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;
            }
        }

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?