HTMLify
Nav Bar with humburger
Views: 251 | Author: djdj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | <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> |