YogeshChauhan . com

The flex-grow, flex-shrink and flex-basis Properties in CSS

in CSS on January 29, 2021

The flex-grow Property

In simple terms, we use flex-grow property to specify how much flex-container child elements will grow relative to other child elements.

We define it in integer value and the default is 0. You can not add negative values.

If all elements have the same flex-grow, then all items will get the same share space.


The flex-shrink Property

This property is the opposite version of flex-grow.

flex-shrink property specifies how much flex-container child elements will shrink relative to other child elements.

Same as flex-grow, we define it in integer value and the default is 0. You can not add negative values.


The flex-basis Property

Using the flex-basis property, we can define the initial size of flex item. It will shrink and grow is there is a room available but initially the element will take the defined size.


How to use flex-grow, flex-shrink, and flex-basis properties together?

We can use flex property. It’s a shorthand property for the flex-grow, flex-shrink, and flex-basis properties.


The following example will make the first element 200px initial size. Twice 0 won’t allow it to grow or shrink. Pretty handy if we have to keep an element in fixed size but need a freedom to adjust the elements nearby.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 7 How to disable right click and drag and drop of images using jQuery? May 7 How to render Lists in React? May 7 What’s the difference between variables in CSS and SCSS (Sass)? May 7 How to define variables in SCSS (Sass)? May 7 How to show and hide an element on click in React? May 5 Use inline if to make a shorter conditional syntax in React

You might also like these

4 ways to create Date Objects in JavaScriptJavaScriptWindow innerHeight and innerWidth properties in JavaScriptJavaScriptWhy it’s not a good idea to create Number objects in JavaScript?JavaScriptHow to display and animate image on scroll using JavaScript?JavaScriptHow to add Laravel to WordPress using Sage theme (and install Tailwind CSS)?PHPThe difference between 400(4xx) and 500(5xx) errorsMisc