Categories
CSS Web development

CSS flex Property

CSS flex Property

The CSS flex property is a shorthand property for:

Syntax:

flex: flex-grow flex-shrink flex-basis|auto;

flex-grow – a number defining how much the item will grow relative to the rest of the flexible items.

flex-shrink – a number defining how much the item will shrink relative to the rest of the flexible items.

flex-basis – the length of the item.

auto – same as 1 1 auto.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
* {
  box-sizing: border-box;
}

.flex-container {
  display: flex;
  flex-wrap: wrap;
  font-size: 30px;
  text-align: center;
}

.item-left {
  background-color: #2a9d8f;
  padding: 10px;
  flex: 50%;
}

.item-right {
  background-color: #e9c46a;
  padding: 10px;
  flex: 50%;
}

@media (max-width: 800px) {
  .item-right, .item-left {
    flex: 100%;
  }
}
</style>
</head>
<body>

<div class="flex-container">
  <div class="item-left">1</div>
  <div class="item-right">2</div>
</div>

</body>
</html>

Output:

1
2

Enjoy coding!