The internet is made up of over 1.7 Billion web pages with different page layouts. Technology nowadays is responsive to any screen orientation or dimension of the screen in our devices. Making page layout comes in handy with the use of Cascading Style Sheet also refers to as CSS. CSS is one of the cornerstones of the web. More like the flesh covering the bones of the body. It is easy to understand and there are lots of resources available on how to use this amazing piece of technology.
So how is this related to our topic?
CSS is use to design layout and the appearance of those web pages but creating multi-layouts is a huddle for beginners who intend to create project with that feature.
To solve these complications, Devs invented proper responsive layout models available natively in the browser, out of which - Flexbox, CSS Grid and Bootstrap became most popular and are widely supported across all platforms & browsers.
I will try to strike the difference between CSS Grid and Flexbox fundamentals and probably when to use which layout.
CSS Grid: This is a two-dimensional grid-based layout system with rows and columns, making it easier to design web pages without having to use floats and positioning. Like tables, grid layout allow us to align elements into columns and rows.
To get started you have to define a container element as a grid withdisplay:grid
, set the column and row sizes withgrid-template-columns
andgrid-template-rows
, and then place its child elements into the grid withgrid-column
andgrid-row
.Flexbox: The CSS Flexbox offers a one-dimensional layout. It is helpful in allocating and aligning the space among items in a container (made of grids). It works with all kinds of display devices and screen sizes.
To get started you have to define a container element as a grid withdisplay: flex;
What is the line of divide between these two?
a. CSS Grid Layout is of two-dimensional , that means it can handle columns and rows, not like flexbox that is basically a one-dimensional.
b. A core distinction between CSS Grid and Flexbox is their approach โ CSS Gridโs
approach is layout-first whereas Flexboxโ approach is content-first.
c. The Flexbox layout is best suited to application components and small-scale layouts, while the Grid layout is designed for larger-scale layouts that are not linear in design.
d. CSS Grid deploys fractional measure units for grid fluidity and auto-keyword functionality to automatically adjust columns or rows.
Top comments (2)
I use grids everywhere, and when I need to use the wrap and reverse functionality from flex, then I switch it to flex, otherwise grids are 95% of the time more than enough.
Awesome! What ever suits your project, work with it. I will surely give your suggestion a try. ๐ช๐ฟ๐ช๐ฟ