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. -w3schools.com
Prior to CSS web developers faced a lot of challenges when designing a layout with HTML and CSS. Tables were used early on but are not responsive. Floats were created to allow content to be aligned on the pages more easily. Floats have trouble with content overflowing outside their container especially on different size viewports. Bootstrap was created to assist with layout design and responsiveness but requires JavaScript to physically change or move the markup. Flexbox was another solution which simplifies the alignment of items on the page, but all these solutions are focused on the content-out rather than the layout-in. CSS Grid, adopted by most modern browsers in 2017, is the first method which can simply move content around different size viewports without altering the HTML markup and can construct the content two-dimensionally.
<style>
.implementation-example {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: repeat(2, 1fr);
grid-gap: .5em;
justify-items: center;
align-items: center;
}
#square1 {
grid-column: 1 / 2;
grid-row: 1 / 2;
}
#square2 {
grid-column: 2 / 3;
grid-row: 1 / 2;
}
#square3 {
grid-column: 1 / 2;
grid-row: 2 / 3;
}
#square4 {
grid-column: 2 / 3;
grid-row: 2 / 3;
}
</style>
<div class="implementation-example">
<figure id="square1">1</figure>
<figure id="square2">2</figure>
<figure id="square3">3</figure>
<figure id="square4">4</figure>
</div>
The named method is a visual way to define your grid. Pages with a lot of content can easily become confusing when trying to manage the rows and columns of a grid. The named method helps offer a visual representation of your grid so that it is easier to read the code.
<style>
.named-example {
display: grid;
grid-template-areas: "box1 box1 box1"
"box2 box3 box4"
"box5 box6 box6";
grid-template-columns: repeat(3 1fr);
grid-template-rows: repeat(3, 1fr);
justify-items: center;
padding: 1em;
}
#box1 {
grid-area: box1; /*no " */
}
#box2 {
grid-area: box2;
}
#box3 {
grid-area: box3;
}
#box4 {
grid-area: box4;
}
#box5 {
grid-area: box5;
}
#box6 {
grid-area: box6;
}
</style>
CSS Grid is a powerful layout solution to problems that have been vexing web developers since the beginning of the Internet. With advancements in a variety of devices such as smartphones, tablets, small laptops like Chromebooks as well as large 4k displays it's never been more important to have a way for content to respond to the size of the viewport that is requesting content. With the help of CSS grid, a new workflow is needed to meet the demand of this assortment of screen sizes as well as aging web browsers that may not support CSS grid. To meet this challenge a new workflow with a mobile-first philosophy is highly encouraged by leaders such as Morten Rand-Hendriksen:
This project was designed and executed with these principles & techniques.