A CSS menu with tabs slider: live demo
In this tutorial, a CSS menu is created which is tabbed style and slides as you click a menu item.
The content of different tabs is contained in the same web page, so it can be used for the single page web site.
The navigation can be done by using mouse click or tab key as well while the menu is responsive (mobile friendly) which is an important factor since more visitors access from mobiles/smart phones these days.
In this demo, the CSS based navigation is created with six items. As you click any item in the top menu, the tabbed style item will open up with the content inside it. First, have a look at the live demo which is followed by a little detail:
See online demo and code
The CSS used:
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
* { box-sizing: border-box; -webkit-tap-highlight-color: rgba(255,255,255,0); } body { line-height: 1.5; font-family: "futura-pt", 'Century Gothic', 'Arial', sans-serif; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; color: #fff; background: #1a1a1a; } a { text-decoration: none; color: inherit; } ul { list-style-type: none; margin: 0; padding: 0; } .css-tab { will-change: transform; position: fixed; top: 0; left: 0; width: 100%; z-index: 1; background: #1a1a1a; -webkit-transform: translateY(-100%); transform: translateY(-100%); -webkit-transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); } .css-tab--active { -webkit-transform: translateY(0); transform: translateY(0); } .css-tab__list { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; } .css-tab__item { -webkit-box-flex: 1; -webkit-flex: 1; -ms-flex: 1; flex: 1; position: relative; -webkit-transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); } .css-tab__item:hover { opacity: 0.75; } .css-tab__thumb { display: block; height: 80px; background: #dc143c; -webkit-transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); } .css-tab__thumb:before { content: attr(data-letter); position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); font-size: 70px; text-transform: uppercase; opacity: 0; } .css-tab__label { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); text-transform: uppercase; letter-spacing: 2px; color: #e6e6e6; margin: 0; } @media (max-width: 850px) { .css-tab__label { font-size: 14px; } } @media (max-width: 720px) { .css-tab__label { display: none; } .css-tab__thumb { height: 60px; } .css-tab__thumb:before { font-size: 24px; opacity: 0.7; } } .tab-content { height: 100vh; will-change: transform; -webkit-perspective: 400px; perspective: 400px; overflow: hidden; -webkit-transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); } .section { will-change: transform; position: absolute; width: 100%; top: 0; left: 0; height: 100vh; overflow: hidden; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; text-align: center; background: #fff; -webkit-transform: translateX(100%); transform: translateX(100%); -webkit-transition: all 0.7s cubic-bezier(0.23, 1, 0.32, 1); transition: all 0.7s cubic-bezier(0.23, 1, 0.32, 1); } .section--hidden { -webkit-transform: translateX(-100%); transform: translateX(-100%); } .section--active { -webkit-transform: translateX(0) rotateY(0); transform: translateX(0) rotateY(0); z-index: 2; } .section__wrapper { width: 100%; max-width: 800px; padding: 0 8vw; position: relative; } .section__title { margin: 0 0 25px 0; font-size: 48px; font-weight: normal; text-transform: uppercase; letter-spacing: 5px; } .section__title:before { content: ''; position: absolute; top: 5rem; left: 45%; margin: auto; width: 10%; height: 2px; background: #fff; } @media (max-width: 720px) { .section__title { font-size: 28px; } .section__title:before { top: 3.25rem; } } .section p { margin: 0 0 25px 0; font-family: 'Georgia'; font-size: 18px; color: #fff; opacity: 0.55; } @media (max-width: 720px) { .section p { font-size: 16px; } } .section p:last-child { margin-bottom: 0; } .color1 { background: #1b1f25; } .color2 { background: #e74c3c; } .color3 { background: #3498db; } .color4 { background: #9b59b6; } .color5 { background: #1bc885; } .color6 { background: #dfb816; } .logo { position: fixed; top: 100px; right: 20px; z-index: 2; } @media (max-width: 720px) { .logo { top: 110px; right: 50%; margin-right: -20px; } } .logo img { width: 45px; -webkit-transform: rotate(0); transform: rotate(0); -webkit-transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); transition: all 0.45s cubic-bezier(0.23, 1, 0.32, 1); } .logo img:hover { -webkit-transform: rotate(180deg) scale(1.1); transform: rotate(180deg) scale(1.1); } |
The markup:
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 |
<nav class="css-tab css-tab--active"> <ul class="css-tab__list"> <li class="css-tab__item"> <a href="" class="css-tab__link"> <div class="css-tab__thumb color1" data-letter="H"></div> <p class="css-tab__label">Home</p> </a> </li> <li class="css-tab__item"> <a href="" class="css-tab__link"> <div class="css-tab__thumb color2" data-letter="C"></div> <p class="css-tab__label">CSS</p> </a> </li> <li class="css-tab__item"> <a href="" class="css-tab__link"> <div class="css-tab__thumb color3" data-letter="J"></div> <p class="css-tab__label">jQuery</p> </a> </li> <li class="css-tab__item"> <a href="" class="css-tab__link"> <div class="css-tab__thumb color4" data-letter="H"></div> <p class="css-tab__label">HTML</p> </a> </li> <li class="css-tab__item"> <a href="" class="css-tab__link"> <div class="css-tab__thumb color5" data-letter="B"></div> <p class="css-tab__label">Bootstrap</p> </a> </li> <li class="css-tab__item"> <a href="" class="css-tab__link"> <div class="css-tab__thumb color6" data-letter="P"></div> <p class="css-tab__label">Python</p> </a> </li> </ul> <a href="https://www.jquery-az.com" class="logo" target="_blank"> <img class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/45226/ettrics-logo.svg" alt="" /> </a> </nav> <div class="tab-content"> <section class="section section--active color1" data-letter="a"> <article class="section__wrapper"> <h1 class="section__title">Home</h1> <p>The Home of web technology tutorials, tips and tricks</p> </article> </section> <section class="section color2" data-letter="p"> <article class="section__wrapper"> <h1 class="section__title">CSS</h1> <p>Style your website by CSS</p> </article> </section> <section class="section color3" data-letter="q"> <article class="section__wrapper"> <h1 class="section__title">jQuery</h1> <p>A powerful and popular Java Script library</p> </article> </section> <section class="section color4" data-letter="e"> <article class="section__wrapper"> <h1 class="section__title">HTML</h1> <p>The web language: Hypertext Markup Language</p> </article> </section> <section class="section color5" data-letter="s"> <article class="section__wrapper"> <h1 class="section__title">Bootstrap</h1> <p>A mobile first web framework</p> </article> </section> <section class="section color6"> <article class="section__wrapper"> <h1 class="section__title">Python</h1> <p>High level popular programming language</p> </article> </section> </div> |
A little jQuery code is also used that you may see and get from the demo page code panel (above the </body> tag).
In the markup section, a <nav> tag is used which is assigned the main css-tab and css-tab—active classes. This is followed by using an unordered list tag with “css-tab__list” class that contains list item (<li>s) with css-tab__item class. The titles for the menu items like CSS, jQuery, Bootstrap etc. are given in the <p> tags.
So, the <nav> tag contains all menu items. After closing the main <nav>, the div for the content area starts with the tab-content class.
For the small screen like smart phones, the word for menu items will be shrunk to the single letter which is specified in the data attribute, data-letter.
Credit: ettrics