Binge On Code

Jun 8, 2023

129 readers

What is the difference between CSS grid and CSS flex?

CSS grid and CSS flex are the most recent CSS layout options, and these come with incredible benefits. However, these are not the same, as explained here.

You may have heard of CSS grid and CSS flex, either in passing, or by your peers, or even in a coding boot-camp. This must have had you wondering, what are these two CSS layout that people keep talking about? Well, here, we get to demystify what they are.

Long story short, CSS grid and CSS flex are just but CSS layout options which can be applied to a container (parent) element such as a div. Think of them as a blueprint which decide how the container element will work, with respect to their child elements.

To be able to answer the high level view of this conundrum on CSS grid and CSS flex, we will do so with a series of simple QA.

So, do they use the same logic?

YES and NO.

Yes because they both take advantage of the dimensional aspect of the parent container(row and column view of a container)

No because, despite the fact that they both treat a container in terms of row and column, they are not the same. Well, to know why CSS grid and CSS flex are not the same with this regard, we will understand what each of these are.

What is CSS grid?

CSS grid is a layout which makes the parent element have a two dimensional CSS layout. What does this mean?

It means that the parent element is envisioned in terms of BOTH rows and columns, instead of just in one direction (row or column)

What is CSS flex?

CSS flex on the other hand is a one dimensional CSS layout. This means that the parent element is envisioned either with respect to the column or the row, but not both.

So, with this layout, you get to CHOOSE ONE direction (no pun intended) you want, a column or a row.

Conclusion

Now you have a simple understanding of CSS grid and CSS flex. It all narrows down to the dimensions of view that the parent will have, when either of these are applied to it.

Well, that is it for now.

Happy Coding!

Related Articles

CSS absolute vs CSS fixed and when to use either

With CSS position, the two common properties are CSS absolute and CSS fixed. This guide resolves the CSS absolute vs CSS fixed argument using a simple example.

Jun 8, 2023

Views 499

What is CSS flex and how do you use it?

CSS flex is an amazing addition to CSS layout list. We will discuss what it is in a few words, and give you a simple introduction to it.

Jun 8, 2023

Views 155

What is css grid – a brief introduction

You may have heard about the term css grid, with your peers or you may have heard the term in passing. This simple introduction will explain what it is.

Jun 8, 2023

Views 150

Angular JavaScript React CSS Django Python React Native Next JS State Management Django Rest Framework Unity