Yogesh Chauhan's Blog

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.

Example

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.

Example

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.

Example

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.

Example

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 add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Implicit and Explicit Joins in Oracle SQLSQL/MySQLJavaScript String fromCharCode() MethodJavaScriptHow to change value of a span tag using a reference from another div using jQuery?jQueryHow to create bouncing balls using HTML canvas and JavaScript?HTMLHow to Find the Highest (or Lowest) Number in an Array in JavaScript?JavaScriptHow does @extend rule work in SCSS (Sass)?SCSS