ハンバーガーメニュー:カード風|Hamburger Menu: Card Style

HTML
<div class="container">
    <div class="hamburger-menu">
        <div class="line"></div>
        <div class="line"></div>
        <div class="line"></div>
    </div>
    <nav class="nav-menu">
        <a href="#">メニュー1</a>
        <a href="#">メニュー2</a>
        <a href="#">メニュー3</a>
    </nav>
</div>
CSS
@keyframes fadeIn {
    0% {
        top: 45%;
        opacity: 0;
    }
    
    100% {
        top: 50%;
        opacity: 1;
    }
}

.container {
    position: relative;
    width: 100%;
    height: 300px;
}

.hamburger-menu {
    width: 40px;
    height: 30px;
    position: absolute;
    top: 20px;
    right: 20px;
    cursor: pointer;
    user-select: none;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: all 0.3s;
}

.hamburger-menu:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.line {
    background-color: #333;
    height: 2px;
    width: calc(100% - 20px);
    position: absolute;
    transition: all 0.3s ease;
    left: 10px;
}

.line:nth-of-type(1) {
    top: 30%;
}

.line:nth-of-type(2) {
    top: 50%;
    transform: translateY(-50%);
}

.line:nth-of-type(3) {
    bottom: 30%;
}

.hamburger-menu.active > .line:nth-of-type(1) {
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

.hamburger-menu.active > .line:nth-of-type(2) {
    opacity: 0;
}

.hamburger-menu.active > .line:nth-of-type(3) {
    bottom: 50%;
    transform: translateY(50%) rotate(-45deg);
}

.nav-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    align-items: center;
    justify-content: center;
    padding: 25px;
    width: 50%;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    opacity: 0;
}

.nav-menu.active {
    display: flex;
    animation: fadeIn 0.5s forwards;
}

.nav-menu a {
    text-decoration: none;
    color: #333;
    padding: 10px;
    margin: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    transition: all 0.3s;
    background: #f9f9f9;
}

.nav-menu a:hover {
    background: #f0f0f0;
    border-color: #ccc;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
JavaScript
document.querySelector('.hamburger-menu').addEventListener('click', function() {
    this.classList.toggle('active');
    document.querySelector('.nav-menu').classList.toggle('active');
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次