Tag 5: Flexbox

Ziel

Lerne, wie du moderne, responsive Layouts einfach mit CSS Flexbox erstellst.

Themen

Flexbox Beispiel

.container {
  display: flex;
  flex-direction: row;       /* Reihe oder Spalte */
  justify-content: space-between; /* horizontale Ausrichtung */
  align-items: center;       /* vertikale Ausrichtung */
  gap: 10px;                 /* Abstand zwischen den Elementen */
}

Übung

Beispiel HTML & CSS

<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="UTF-8">
  <title>Flexbox Übung</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 für Boxen */
    .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="#">Start</a>
    <a href="#">Über</a>
    <a href="#">Kontakt</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>