Common Flex Layouts

Perfect Centering

Example

Center anything horizontally and vertically:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .stage { display: flex; justify-content: center; align-items: center; height: 140px; background: #282A35; }
    .stage div { background: #04AA6D; color: white; padding: 14px 22px; font: 16px Arial; border-radius: 6px; }
  </style>
</head>
<body>

<div class="stage"><div>Centered</div></div>

</body>
</html>

Result

Navigation Bar

Example

Logo on the left, links on the right:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    nav { display: flex; align-items: center; justify-content: space-between; background: #282A35; padding: 10px 16px; font-family: Arial; }
    .logo { color: #04AA6D; font-weight: bold; font-size: 20px; }
    .links { display: flex; gap: 16px; }
    .links a { color: white; text-decoration: none; }
    .links a:hover { color: #04AA6D; }
  </style>
</head>
<body>

<nav>
  <div class="logo">Careeroza</div>
  <div class="links"><a href="#">Home</a><a href="#">Courses</a><a href="#">Jobs</a></div>
</nav>

</body>
</html>

Result

Cards That Wrap

Example

Cards with a minimum width that wrap to new lines on small screens (resize the code runner to see it):

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .cards { display: flex; flex-wrap: wrap; gap: 12px; font-family: Arial; }
    .card { flex: 1 1 160px; border: 1px solid #ddd; border-radius: 8px; padding: 12px; }
    .card h3 { margin: 0 0 6px; color: #04AA6D; }
  </style>
</head>
<body>

<div class="cards">
  <div class="card"><h3>HTML</h3>Structure</div>
  <div class="card"><h3>CSS</h3>Style</div>
  <div class="card"><h3>JS</h3>Behaviour</div>
</div>

</body>
</html>

Result