9.3 Student Activity

Build a Responsive Navigation Bar Using Flexbox

  1. Step 1:

    • HTML Structure: Create an HTML file (flex-navbar-9.2.html) with a navigation bar that includes a logo and links:

      <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="UTF-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <link rel="stylesheet" href="basic.css" />
          <link rel="stylesheet" href="index.css" />
          <style>
          
            body {
              font-family: Arial, sans-serif;
            }
            @media screen and (max-width: 600px) {
              .container {
                flex-direction: column;
                gap: 10px;
              }
            }
          </style>
          <title>Document</title>
        </head>
        <body>
          <div class="container">
            <div class="logo">My Logo</div>
            <div class="home">Home</div>
            <div class="about">About</div>
            <div class="contact">Contact</div>
          </div>
        </body>
      </html>
  2. Step 2:

    • Using Flexbox for Layout:

      • The .container uses Flexbox to arrange the logo and the div elements side-by-side on larger screens.

      • Set align-self to flex-end, flex-center, or flex-start to see the effect.

      • For smaller screens, media queries are used to stack the items vertically.

  3. Step 3:

    • Responsive Behavior: Test the layout by resizing the browser window. The layout should adjust from a horizontal layout on larger screens to a vertical stack on smaller screens.

  4. Step 4:

    • Use css-studentactivity-9.2.html to scale the flex-nav-links items individually using CSS styles of container class in index.css :

    • Adjust height and width properties to change the size of nav menu item (Home, About, Services, Contact)

    • Inspect the changes to the layout by resizing the value of the Height property of the container class attribute to less than 100%.

Last updated