DEV Community

Cover image for CSS Grid Explained: How To Become A CSS Grid Master
👨‍💻Rohit 🪄
👨‍💻Rohit 🪄

Posted on

CSS Grid Explained: How To Become A CSS Grid Master

The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.

Section 1: What Is CSS Grid?

In its simplest form, CSS Grid defines eight major properties, each one triggering an effect when applied to the body element:

grid-template-columns — sets the baseline size for each row of the grid. This determines the size of each column.

— sets the baseline size for each row of the grid. This determines the size of each column. grid-template-rows — sets the spacing for each row. This determines the size of each column.

— sets the spacing for each row. This determines the size of each column. grid-gap — controls how much space between the row elements and columns.

— controls how much space between the row elements and columns. grid-template-areas — defines how grid rows and columns are supposed to be used (in terms of spacing).

How Does The CSS Grid System Work?

Let's take a closer look at how the grid system works in CSS.

The following code shows a screencast showing how to set a CSS grid system using Sass.

To create a CSS grid system, all we need is a grid, a container, and some content. A simple grid will look something like this:

There are three HTML markup elements you need to make the basic layout work. A new section of code in the layout element:

What The CSS Grid Algorithm Does

First, let's look at the HTML markup elements we need to use to create a CSS grid layout.

CSS Grid Layout's content and grid. There is a column-based grid which means each row has a column of content. This may look something like this:

There is a row-based grid which means each row has a row of content.

What Are The Advantages Of Using The CSS Grid System?

That’s the question many web developers are asking themselves. After all, floats and other box-based layouts have been around for decades, so what’s so great about the CSS Grid Layout?

The answer is in the name – CSS Grid Layout is a grid-based layout system which is more efficient and structured compared to floats. It has been made for the next generation of web design, combining simplicity with flexibility and reliability.

Before going any further, a few important notes:

No longer an experimental project, the CSS Grid Layout Module has been formally adopted by the W3C as an official specification.

It is designed to work across all browsers including IE11 and older versions.

How Do You Become A CSS Grid Master?

CSS Grid Layout Explained: How To Become A CSS Grid Master

Chances are you’re coming to the CSS Grid Layout, or the CSS Grid Module, for the first time today. Most of you already know what it is, and are still wondering how to become a CSS Grid master.

“What is the CSS Grid Layout?” is the first question you’ll be asked. The CSS Grid Layout was developed by Jake Archibald, currently the community manager at Microsoft. He was inspired to create CSS Grid after working on the previous Microsoft Edge blog, where he produced a manual layout system for the browser.

Practice, Practice, Practice!

Here’s a simple exercise for you: write down three tasks that you must accomplish in the next 10 minutes. Maybe it’s something small like remembering to buy milk and coffee, or it could be a more serious matter like finding out if a friend is okay after he or she accidentally got caught up in an accident. Whatever the task, we’re talking about putting pen to paper right now and finishing it in that timeframe.

Now, follow the logic of the time constraint: you’ve got 10 minutes to complete three tasks. To do that, you have to complete your tasks quickly, be decisive, and eliminate distractions.

Any of these characteristics can be traced back to business intelligence — a discipline that, over the years, has become embedded in every company’s DNA.

Learn the Rules of the Game

In CSS, it's easy to create some absolute divs. These elements have special behaviour, and so are defined by the CSS rules.
Learn to break these rules.

Learn to create floats.

Learn to use floats to define your own layout - not as it was defined in CSS before, but as you want it to be.

Learn about positioning in the rows and columns, and how to use - or break - the rules about positioning.

Introduction to Preprocessors:

With CSS preprocessors, it's now possible to define an element, and give it all its visual appearance, even its colors, using the syntax of a CSS file.

Why Use Preprocessors.

Preprocessors let us define styles directly, and without having to load fonts and images first.

Use a Tool

Other tools to design a custom grid layout include:

Flashercase

Flashercase provides grid-based layouts with grids, borders and tabs, and supports grids by gridcell, column, row and table.

Hexgrid:
With Hexgrid you can easily create a customizable template or pattern with many options to suit your design and development needs.

GridWiz:
You can easily design a cross-browser compatible responsive grid and layouts that are optimized for mobile, tablet, and desktop.

Terraform:
Terraform allows you to easily build and theme a website. With the option of designing a grid layout for your website, you can easily make sure your website is compatible with mobile devices, works with web browsers with varying features, and is optimized for delivery with HTML5 and CSS3.

Keep it Simple.

The CSS Grid Layout Module is specifically designed to be used on desktop and mobile devices. Users can download it as either a CSS or a HTML module and use either of them to create their layouts. But note that it may still be too early to start designing and developing grids for both versions of IE11 and Android.

A Solid Foundation.
While the flexibility of the CSS Grid Layout Module might seem overwhelming, starting out with just four basic properties will ensure that your layout is mostly complete.

Top comments (0)