CSS
π― CSS flex-basis Property
The flex-basis CSS property defines the initial size of a flex item before any growing or shrinking occurs.
It determines how much space an element takes inside a Flexbox container at the start of layout distribution.
πΉ Why Use flex-basis?
-
Benefits
- π Defines initial item size in Flexbox
- π Works with flex-grow and flex-shrink
- π Helps create predictable layouts
- π Useful for responsive design control
πΉ flex-basis Values
- auto β Default size based on content
- length β Fixed size (px, %, rem, etc.)
- initial β Resets to default (auto)
π§© Basic Example
CSS
.container {
display: flex;
}
.item {
flex-basis: 150px;
}
In this example, each flex item starts with a base width of 150px before growing or shrinking.
-
π§ Quick Summary
- flex-basis β defines the initial size of a flex item
- auto β uses content-based size
- length β sets fixed size (px, %, rem, etc.)
- initial β resets to default value
