Categories
Web development

CSS flex-basis Property

CSS flex-basis Property

The CSS flex-basis property defines the initial length of a flexible item.

Syntax:

flex-basis: number|auto;

number – a length unit, or percentage, defining the initial length of the flexible item(s).

auto (default) – the length is equal to the length of the flexible item.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
#box-container {
  width: 300px;
  height: 100px;
  border: 3px solid #333;
  display: flex;
}

#box-container div {
  flex-grow: 0;
  flex-shrink: 0;
  flex-basis: 50px;
}

#box-container div:nth-of-type(3) {
  flex-basis: 100px;
}
</style>
</head>
<body>

<div id="box-container">
  <div style="background-color:#264653;">50px</div>
  <div style="background-color:#2a9d8f;">50px</div>
  <div style="background-color:#e9c46a;">100px</div>
  <div style="background-color:#f4a261;">50px</div>
  <div style="background-color:#e76f51;">50px</div>
</div>

</body>
</html>

Output:

50px
50px
100px
50px
50px

Note: Internet Explorer 10 and earlier versions do not support the flex-basis property!

Enjoy coding!

Read also:

CSS align-content Property

CSS flex-wrap Property