This content originally appeared on DEV Community and was authored by alok-38
When working with Flexbox layouts, you might want one element — like a sidebar — to stay fixed while another area stretches to fill the rest. The flex shorthand property lets you control that with precision. Here’s how flex: 0 0 255px achieves it.
What flex: 0 0 255px Means
flex: 0 0 255px; /* sidebar stays fixed */
Broken down:
flex-grow: 0 → the sidebar will not grow to take up extra space.
flex-shrink: 0 → the sidebar will not shrink if the container gets smaller.
flex-basis: 255px → the sidebar’s starting (and effectively final) width is 255px.
Before and After Example
Before applying flex: 0 0 255px
After applying it
In summary
flex-grow: 0prevents the sidebar from expanding.flex-shrink: 0prevents it from collapsing.flex-basis: 255pxsets its exact width.
This content originally appeared on DEV Community and was authored by alok-38
alok-38 | Sciencx (2025-11-03T03:34:31+00:00) How the Flex-Basis Property Works in CSS Flexbox. Retrieved from https://www.scien.cx/2025/11/03/how-the-flex-basis-property-works-in-css-flexbox/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.

