Mar 26, 2019
CSS grid and its benefits
Over the past few years CSS grid systems have grown a lot in popularity. After landing in browser in early 2017, it quickly becoming considered best practice for rapid layout scaffolding. Until then you will need to enable grid for it to work.
So, what is a css grid system?
In basic terms, a css grid system create a structure that allows for content to be stacked both vertically and horizontally in a consistent and easily manageable fashion. Grid and flexbox can act in similar ways. You may have seen people using flexbox to construct grid systems but that's not what flexbox was designed for.
CSS grid layout method is designed for the two-dimensional layout of items on a webpage or application. Grid Layout gives us a method of creating grid structures that are described in CSS and not in HTML. It helps us to create layouts that can be redefined using Media Queries and adapt to different contexts. Grid Layout allows us properly separate the order of elements in the source from their visual presentation. It’s very easy to make grid adapt to the available space. With each element having an area on the grid, things are not in risk of overlapping due to text size change, more content than expected or small viewports.
CSS Grid layout excels at dividing a page into major regions, or defining the relationship in terms of size, position, and layer, between parts of a control built from HTML primitives.
Like tables, grid layout enables an designer to align elements into columns and rows. However, many more layouts are either possible or easier with CSS grid than they were with tables.
Benefits of CSS Grid layout
Reduced code bloat
Rather than creating extra HTML elements to contain your grid, columns, and rows, your grid tracks are created within your stylesheet.
Frameworks like Bootstrap often compel developers to venture into divitis territory. What’s more, grid frameworks don’t always use the most semantically sound class names.
Reduced file sizes
As CSS Grid is native, there is no need to include large libraries like Bootstrap in your projects.
Speed of development
Once you learn the syntax, prototyping with CSS Grid is fast and efficient.
It also became possible to style labels based on the state of their field using adjacent sibling selectors - for example, applying bold to a label when its associated checkbox is checked.
A grid is two-dimensional and respects both rows and columns. If an element is too big for its cell, the row and/or column will grow accordingly. A grid is ideal for page and form layout.
The CSS Grid Layout is also useful for styling such smaller components as content sections with blog posts or the blog posts themselves.
the CSS Grid Layout gives us the possibility to easily change the placement of the grid items according to the device screen.