【部品】hambuger button

<div id="nav-drawer">
        <input id="nav-input" type="checkbox">
        <label id="nav-open" for="nav-input">
            <div id="hamburgerBtn">
                <span></span>
                <span></span>
                <span></span>
            </div>
        </label>
        <label id="nav-close" for="nav-input"></label>
        <nav id="nav-content">
            <ul>
                <li><a href="#">section1</a></li>
                <li><a href="#">section2</a></li>
                <li><a href="#">section3</a></li>
            </ul>
        </nav>
    </div>
:root{
    --nav-open__size: 51px;
    --nav-open__bgColor: #333;
    --hamburgerBtn__size: 21px;
    --hamburgerBtn__color: #fff;
    --menu__size--width: 70%; 
    --menu__size--height: 100%; 
}

#nav-input{
    display: none;
}

#nav-open {
    width: var(--nav-open__size);
    height: var(--nav-open__size);
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--nav-open__bgColor);
}

#hamburgerBtn{
    width: var(--hamburgerBtn__size);
    height: var(--hamburgerBtn__size);
    position: relative;
}

#hamburgerBtn span{
    width: 100%;
    height: 14%;
    background-color: var(--hamburgerBtn__color);
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s ease;
}
#hamburgerBtn span:nth-child(1) {
    top: calc(50% - 30%);
}
#hamburgerBtn span:nth-child(3) {
    top: calc(50% + 30%);
} 

#nav-content {
    z-index: 1001;
    display: block;
    background-color: #fff;
    width: var(--menu__size--width);
    height: var(--menu__size--height);
    position: fixed;
    right: 0;
    transform: translateX(110%);
    transition: 0.3s ease-in-out;
    box-shadow: 10px 5px 25px rgba(0, 0, 0, 0.9);
}

#nav-input:checked~#nav-open span:nth-child(2) {
    transform: scaleX(0);
    transition-delay: 0s;
}

#nav-input:checked~#nav-open span:nth-child(1) {
    transform: translateY(200%) rotate(-45deg);
    transition-delay: 0.15s;
}

#nav-input:checked~#nav-open span:nth-child(3) {
    transform: translateY(-200%) rotate(45deg);
    transition-delay: 0.15s;
}

#nav-input:checked~#nav-close {
    z-index: 1000;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0.5;
}

#nav-input:checked~#nav-content {
    transform: translateX(0%);
}

コメント

タイトルとURLをコピーしました