Day 5: Flexbox

Goal

Learn how to create modern, responsive layouts easily using CSS Flexbox.

Topics

Flexbox Example

.container {
  display: flex;
  flex-direction: row;       /* row or column */
  justify-content: space-between; /* horizontal alignment */
  align-items: center;       /* vertical alignment */
  gap: 10px;                 /* space between items */
}

Practice

Example HTML & CSS

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Flexbox Practice</title>
  <style>
    body {
      font-family: Arial, sans-serif;
    }

    /* Navbar */
    nav {
      display: flex;
      justify-content: space-between;
      background-color: #2c3e50;
      padding: 10px 20px;
      color: white;
    }

    nav a {
      color: white;
      text-decoration: none;
      margin: 0 10px;
    }

    /* Flexbox container for boxes */
    .flex-container {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 10px;
      margin-top: 20px;
    }

    .box {
      background-color: #3498db;
      color: white;
      width: 30%;
      height: 100px;
      display: flex;
      justify-content: center;
      align-items: center;
      font-weight: bold;
    }
  </style>
</head>
<body>

  <h1>Flexbox Layout</h1>

  <nav>
    <a href="#">Home</a>
    <a href="#">About</a>
    <a href="#">Contact</a>
  </nav>

  <div class="flex-container">
    <div class="box">Box 1</div>
    <div class="box">Box 2</div>
    <div class="box">Box 3</div>
  </div>

</body>
</html>