Watching:

What is a CSS grid?


show more What is a CSS grid? provides you with in-depth training on Developer. Taught by James Williamson as part of the CSS: Frameworks and Grids show less
please wait ...

What is a CSS grid?

It would be nice if laying out pages with CSS were easier. As it is, the quirks of crafting float-based layouts can be challenging, even for the most experienced designers. So while we wait on support for new layout models like Flexbox and CSS grid Templates, it's not unreasonable to look for some way to speed up and simplify the process of crafting page layouts. That's where CSS grid systems come in. A grid system is a collection of styles that allows a designer to control page layout based on using rows and columns. A typical grid system works like this.

Containing elements are used to define a row within the layout, then you apply class attributes to child elements and then span them over the desired number of columns within that row. The grid system will typically be based on a 12- to 16-column grid. The grid could be fixed, meaning the columns are based off of a set width, or they could be fluid or percentage based. Either way, the grid system will have a collection of styles that will float an element and then tell it how many columns to span.

The containing element will then handle clearing the floats and establishing a new section of content. Most frameworks come with built-in grid systems, but there are quite a few stand-alone grids available for designers who want the ease of using grids without the overhead of an entire framework. As with any predefined system, there are pros and cons to using grids. The most obvious pro is the speed with which they let you work. You can often craft a simple layout in seconds by just applying a few classes. They can also reduce the frustration typically involved with pretty more complicated nested layouts as the CSS is written to account for many of the float-based issues that often plague complex layouts.

However, they are not without their downsides. Most grid systems require you to use containing elements for rows and columns. This means the injection of somewhat unnecessary code into your HTML. This can be especially tricky when attempting to utilize a grid system with a CMS that generates a different code structure. Another consideration is the class attributes that grid systems use. The values are usually specific to the grid that forces you to inject a fair amount of non-semantic markup into your code. Grid systems can also be somewhat inflexible if you're using media queries to target multiple screen sizes, because the classes are tied to a specific column value, it can be difficult to create layouts that shift significantly from one screen size to the next.

In many ways, grid systems are much like the frameworks that often contain them. Some designers swear by them, while others see them as adding unnecessary weight to their code. If you have never used one, I recommend trying one out to see it increases your efficiency and fits with your design philosophy.

What is a CSS grid?
Video duration: 2m 40s 3h 27m Beginner

Viewers:

What is a CSS grid? provides you with in-depth training on Developer. Taught by James Williamson as part of the CSS: Frameworks and Grids

Subjects:
Developer Web
Software:
CSS
Author:
please wait ...