Yogesh Chauhan's Blog

How to make flexbox items of the same size?

in CSS on March 27, 2021

CSS flexbox, just like CSS grid, is really handy when it comes creating a powerful, robust and responsive structure across all devices.

In CSS grid, it’s a bit easier to make the items of equal width. In a flexbox, it’s not hard but it just take a complete understanding of how the flex properties work.

Look at these examples below with few flex items.

As you can see in the first example, when we have items with same number of characters, it doesn’t require any width adjustment. But as you can see in the second example, when we have different kinds of content in different flexbox items then it it requires some kind of width adjustment to make it look good.

You can try to adjust the width of the individual flex items but there is an easier way to do that.

We can use flex shorthand property to make the flex items of equal width.

Just like this example:

flex property is a shorthand property for the flex-grow, flex-shrink, and flex-basis properties. So, if you’d like, you can use all 3 properties separately as well. Just like this example.


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to check if a link has http or https in it in JavaScript?JavaScriptIs there a difference between SCSS and Sass?SCSSHow to vertically and horizontally align text and image block (without flex or grid) in CSS?CSSA Step by Step Guide to Make RSS in XML For Any Website or Blog For FreeMiscellaneousAND, OR and NOT boolean operators in Envision BasicEnvision BasicSequence generator (range) using JavaScript Array.from()JavaScriptArray.from() Method in JavaScriptJavaScriptHow to Recognize an Array in JavaScript?JavaScriptAngular: Templates, directives, data binding, Services and dependency injectionAngularHow to create a simple digital clock using JavaScript?JavaScriptCheck if mixin is being called in a style rule or not in SCSSSCSSHow to remove trailing characters from a string using JavaScript?JavaScript