Log in Register Dashboard Temp Share Shortlinks Frames API

HTMLify

Nav Bar with humburger
Views: 105 | Author: djdj
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Responsive Navbar</title>
  <style>
    body {
      margin: 0;
      font-family: 'inknut antiqua';
    }

    nav {
      width: 100%;
      background: #fff;
      padding: 15px 25px;  /* thoda zyada spacing */
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: relative;
      box-sizing: border-box;
      border-bottom: 1px solid #ddd;
    }

    /* Logo */
    .logo {
      font-family: 'Playfair Display', serif;
      font-size: 22px;
      font-weight: bold;
      color: #333;
    }

    /* Menu list */
    .menu {
      list-style: none;
      display: flex;
      gap: 25px; /* thoda gap bada */
      margin: 0;
      padding: 0;
      font-weight: bold;
      font-size: 17px;
    }

    /* Menu links */
    .menu li a {
      font-family: 'Playfair Display', serif;
      text-decoration: none;
      color: #333;
      position: relative;
      transition: color 0.3s;
      padding: 8px 5px; /* thoda vertical spacing */
    }

    .menu li a:not(.book-now)::after {
      content: "";
      position: absolute;
      bottom: 0; /* underline aur neat lage */
      left: 0;
      width: 0;
      height: 2px;
      background: blue;
      transition: width 0.3s;
    }

    .menu li a:not(.book-now):hover {
      color: blue;
    }

    .menu li a:not(.book-now):hover::after {
      width: 100%;
    }

    /* Book Now Button */
    .book-now {
      font-family: 'Lato', sans-serif;
      border: 2px solid blue;
      padding: 8px 18px;
      border-radius: 5px;
      color: #3982ef;
      text-decoration: none;
      transition: all 0.3s;
    }
    .book-now:hover {
      background: blue;
      color: #fff !important;
    }
    .book-now::after {
      display: none !important;
    }

    /* Hamburger */
    .hamburger {
      display: none;
      flex-direction: column;
      cursor: pointer;
      gap: 6px;
    }
    .hamburger span {
      width: 28px;
      height: 3px;
      background: #333;
      border-radius: 2px;
    }

    /* ===== Responsive ===== */
    @media(max-width: 768px) {
      .menu {
        flex-direction: column;
        background: #fff;
        position: absolute;
        top: 60px;
        left: 0;
        width: 100%;
        overflow: hidden;
        max-height: 0;
        transition: max-height 0.5s ease;
        box-shadow: 0 5px 10px rgba(0,0,0,0.1);
        padding: 0 20px; /* horizontal padding */
      }
      .menu li {
        width: 100%;
        text-align: left;
        padding: 10px 0; /* vertical spacing for items */
        border-bottom: 1px solid #eee; /* optional divider */
      }
      .menu li:last-child {
        border-bottom: none;
      }
      .menu.active {
        max-height: 500px;
        padding: 15px 20px; /* space when expanded */
      }
      .hamburger {
        display: flex;
      }
    }
  </style>
</head>
<body>

  <nav>
    <div class="logo">My Logo</div>
    <ul class="menu" id="menu">
      <li><a href="#">Home</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Option 1</a></li>
      <li><a href="#">Option 2</a></li>
      <li><a href="#" class="book-now">Contact Now</a></li>
    </ul>
    <div class="hamburger" id="hamburger">
      <span></span>
      <span></span>
      <span></span>
    </div>
  </nav>

  <script>
    const hamburger = document.getElementById("hamburger");
    const menu = document.getElementById("menu");

    hamburger.addEventListener("click", () => {
      menu.classList.toggle("active");
    });
  </script>

</body>

Comments