白背景 × 青ラインのハンバーガーメニュー

HTML
<div class="hamburger-wrapper">
  <button class="hamburger-style3" id="hamburger-btn">
    <span></span>
    <span></span>
    <span></span>
  </button>
  <nav class="hamburger-nav" id="hamburger-nav">
    <ul>
      <li><a href="#">HOME</a></li>
      <li><a href="#">ABOUT</a></li>
      <li><a href="#">SERVICE</a></li>
      <li><a href="#">CONTACT</a></li>
    </ul>
  </nav>
</div>
CSS
body {
  margin: 0;
  padding: 0;
  background: #fff;
}

.hamburger-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 40px 0;
}

.hamburger-style3 {
  width: 50px;
  height: 50px;
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  padding: 0;
  z-index: 10;
}

.hamburger-style3 span {
  position: absolute;
  width: 100%;
  height: 4px;
  background-color: #007bff;
  border-radius: 2px;
  left: 0;
  transition: all 0.3s ease;
  transform-origin: center; /* 中心を回転軸に指定 */
}

.hamburger-style3 span:nth-child(1) {
  top: 12px;
}

.hamburger-style3 span:nth-child(2) {
  top: 23px;
}

.hamburger-style3 span:nth-child(3) {
  top: 34px;
}

/* × に変形 */
.hamburger-style3.active span:nth-child(1) {
  transform: rotate(45deg);
  top: 23px;
}

.hamburger-style3.active span:nth-child(2) {
  opacity: 0;
}

.hamburger-style3.active span:nth-child(3) {
  transform: rotate(-45deg);
  top: 23px;
}

/* メニュー */
.hamburger-nav {
  display: none;
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  background: #fff;
  border: 1px solid #ddd;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.hamburger-nav.open {
  display: block;
}

.hamburger-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.hamburger-nav ul li a {
  display: block;
  padding: 14px 16px;
  text-decoration: none;
  color: #333;
}

.hamburger-nav ul li a:hover {
  background: #f0f0f0;
}
JavaScript
document.getElementById("hamburger-btn").addEventListener("click", function() {
  this.classList.toggle("active");
  document.getElementById("hamburger-nav").classList.toggle("open");
});

🌟 有料会員限定素材を配布中!

ここでしか手に入らない特別デザイン素材を今すぐチェック!

有料会員ページを見る
目次