Fireship · @fireship

Animated Responsive Navbar with CSS - Plus Other Useful Tricks

Uploaded February 28, 2020 · Length 11:40

Animated Responsive Navbar with CSS - Plus Other Useful Tricks

Summary

Build a responsive navigation menu from scratch using plain CSS, including Flexbox, transitions, and media queries.

  • responsive navbar
  • css from scratch
  • flexbox
  • css transitions
  • media queries
  • css layout

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    You don't need Bootstrap, and you definitely don't need to pay for an expensive theme to

  2. 0:03

    add a beautiful navigation layout to your web app.

  3. 0:06

    Today we'll build a responsive navigation menu from scratch using nothing but plain

  4. 0:10

    CSS.

  5. 0:11

    You'll learn how to use Flexbox to position things, transitions to animate things, and

  6. 0:14

    media queries to make things responsive.

  7. 0:16

    And I'll throw in a bunch of other small tricks like duotone icons, transforms, filters,

  8. 0:20

    and more.

  9. 0:21

    If you're new here, make sure to subscribe, and if you want to see more project-focused

  10. 0:25

    videos like this, make sure to hit the like button and leave me a comment below.

  11. 0:28

    Let's start by taking a closer look at what we're actually building.

  12. 0:31

    We have a navigation bar that's fixed to the left side, taking up the full height of

  13. 0:35

    the viewport.

  14. 0:36

    If you hover over it, it animates out, showing text for each individual item.

  15. 0:40

    And notice how the arrow at the top rotates in and out of place depending on the hover

  16. 0:43

    state.

  17. 0:44

    Now hovering over an individual item will animate the background color as well as the colors

  18. 0:48

    in the SVG icon itself, which gives you a subtle but also very cool looking duotone effect.

  19. 0:54

    Now we'll be using Flexbox to lay everything out, which makes it really easy to convert

  20. 0:58

    a column into a row.

  21. 1:00

    So we'll use a media query for small devices to take the navbar and fix it to the bottom.

  22. 1:05

    And that should provide a much better experience on mobile, assuming that your app is intended

  23. 1:08

    to be used in portrait mode.

  24. 1:10

    That gives us a good starting point, so let's go ahead and jump right into the code.

  25. 1:13

    Now this video is designed for you to follow along, but we'll be moving at a very quick

  26. 1:17

    pace, so feel free to slow down the playback speed or pause if necessary.

  27. 1:21

    You'll notice I have an index.html file, and a style.css file which is referenced in

  28. 1:26

    the head of that HTML document.

  29. 1:28

    And you'll also notice I have a custom font from Google Fonts, feel free to use whatever

  30. 1:32

    font you prefer.

  31. 1:33

    Now moving on to the body of the HTML, we have a nav element, which is the main thing

  32. 1:37

    we're building today.

  33. 1:38

    Then alongside that, we have a main element to hold the main content of the page, and

  34. 1:42

    right now it's just filled up with a bunch of hipster ipsum.

  35. 1:45

    Currently, our HTML is completely unstyled.

  36. 1:48

    Let's start by setting a few values we can reuse throughout our CSS on the root pseudo

  37. 1:52

    class selector.

  38. 1:54

    We can set the font size here, and we'll also define a few custom properties, aka variables,

  39. 1:59

    that represent the theme of the application.