Iaweb ws2019 g1 Survey Css Grid
Iaweb ws2019 g1 Survey Css Grid
30 Nov 2019
Abstract
This paper aims to introduce a state-of-the-art way to layout web pages in CSS, introducing
CSS Grid. This work gives an introduction to CSS Grid and its most important principles,
properties, features and options, showcasing why Grid is recommended to use compared
to older techniques. Furthermore, this paper explores Grid Generators, including available
tools online and evaluating their usefulness. This paper introduces the latest browser tools
to examine the grid in the browser source inspectors. All things considered, this paper wants
to give an overview of a fairly new topic in web page layout design with CSS.
This work is placed under a Creative Commons Attribution 4.0 International (CC BY 4.0) licence.
Contents
Contents i
List of Listings v
Bibliography 21
i
ii
List of Figures
iii
iv
List of Listings
v
vi
Chapter 1
If one wants to understand which improvements CSS Grid brought and which issues it fixed, one first
needs to understand which layout-techniques existed before it and what problems they had to cope
with. Therefore, we want to give a quick introduction to historical methods to give an impression on
the evolvement of layout options in CSS. It is worth to mention that those techniques are not all that
‘historical’ themselves as they are still widely used all across the web as CSS Grid is fairly new.
1.1 Float
The early layouts in CSS used Floats. The main content was often given a margin to have space for placing
elements. In that time one could have elements on a website overflowing each other when increasing the
font size for example. But what is Floating? It is a CSS Method of positioning elements by moving them
as one would do with an image in Microsoft Word. If one uses the Float keyword in CSS the element
gets moved to the desired direction [Andrew 2017].
The float property can have following values:
• left - movement to the left
1.2 Flexbox
Many issues were fixed with the introduction of Flexbox. The so-called Flexible Box module brought
features that were designed for responsive web. When using Flexbox one makes the items in the parent
tag, called the flex container, stretch inside their container to adjust to screen size. These items are called
flex items and can be reordered in CSS without interfering with the HTML source code. Items can be
told to wrap into multiple lines with the "wrap" property.
However, one still needs a parent element inside the HTML that takes the role of the flex container.
Another downside is that one lays out items either in column or row. One can not control both in a single
Flexbox.
1
2 1 The History Of Layout In CSS
From this, it should be obvious that Flexbox is not designed for grid layouts. But in many cases,
designers want to lay out in two dimensions. Once again, workarounds were the only possibility to reach
desired results [Andrew 2017].
The CSS Grid module has many useful features. These range from positioning to responsiveness and
layout changes. This chapter will take a look at the most import ones and give examples for them.
Simple numbers are then used to choose the correct cell. This can be shortened further by using single
"/" for separation of the start and endpoint.
# positioning-with-grid .b {
grid-column : 2 / 3;
grid-row : 2 / 3;
}
The user can also define aliases instead of using numbers if preferred.
# positioning-with-grid .c {
grid-column : col 3;
grid-row : row 2;
}
To stretch an element over more than one cell, the "span" keyword can be used.
# positioning-with-grid .d {
grid-column : 1 / 2;
grid-row : 1 / span 2;
}
3
4 2 Features of CSS Grid Module
Listing 2.1: This is the simple HTML code used in the examples of Section 2.1
Figure 2.1: This is a screenshot of the output of the examples of Section 2.1.
If space is a concern, the area can be defined in a single line sacrificing readability for space. The order
of the numbers is "row-start", "column-start", "row-end", and "column-end".
# positioning-with-grid .f {
grid-area : 1 / 3 / 2 / 4;
}
Figure 2.2: This screenshot shows various features of Grid like absolute positioning and layering.
Listing 2.2: This is the simple HTML code used in various examples.
1 # grid-repeat . wrapper {
2 ...
3 grid-template-columns : repeat (5, [col] 12 rem ) ;
4 grid-template-rows : repeat (3, [row] auto );
5 }
Listing 2.3: In this example, a template is created with the repeat keyword allowing for a quick
formal layout.
6 2 Features of CSS Grid Module
1 # grid-layering . clocktower {
2 ...
3 position : absolute ;
4 top: 1rem;
5 right : 1rem;
6 }
Listing 2.5: This is the simple HTML code used for the responsive examples.
corresponding CSS code can be seen in Listing 2.4. A screenshot of the output is shown in Figure 2.2
and the corresponding HTML code in Listing 2.2.
1 # example . wrapper {
2 grid-template-areas :
3 " header header "
4 " sidebar content "
5 " sidebar2 sidebar2 "
6 " footer footer ";
7 }
Listing 2.6: Creating Areas is very intuitive and straightforward. The general Grid is simply laid out
by organizing the titles of the cells. To add an element, only the alias needs to be added.
8 2 Features of CSS Grid Module
1 # example-template . wrapper {
2 grid-template-columns : 1fr 3fr 1fr;
3 grid-template-rows : 20% 40% auto;
4 grid-template-areas :
5 " header header header "
6 " sidebar content sidebar2 "
7 " footer footer footer ";
8 }
9
10 . header {
11 grid-area : header ;
12 }
Listing 2.7: Creating Areas is very intuitive and straightforward. The general Grid is simply laid out
by writing the aliases of the cells. To then add an element to a cell, only the alias needs
to included in its "grid-area" tag.
Media Queries and CSS Grid 9
1 # media-queries . wrapper {
2 display : grid;
3 grid-template-areas :
4 " header "
5 " sidebar "
6 " content "
7 " sidebar2 "
8 " footer "
9 }
10
11 @media only screen and ( min-width : 40 rem) {
12 # media-queries . wrapper {
13 grid-template-columns : 1fr 3fr;
14 grid-template-areas :
15 " header header "
16 " sidebar content "
17 " sidebar2 sidebar2 "
18 " footer footer ";
19 }
20 }
21
22 @media only screen and ( min-width : 60 rem) {
23 # media-queries . wrapper {
24 grid-template-columns : 1fr 3fr 1fr;
25 grid-template-areas :
26 " header header header "
27 " sidebar content sidebar2 "
28 " footer footer footer ";
29 }
30 }
Listing 2.8: This is an example of a layout having three different versions for different screen sizes
using media queries.
2.8 Layering
Elements of a Grid can be layered on top of each other with the property "z-index". This adds a third-
dimension to layouts. The furthest back position would be at zero, and each increase by one is one layer
further to the front. This can also be nicely combined with transparencies. A screenshot of the output is
shown in Figure 2.2 and the corresponding HTML code in Listing 2.2.
# grid-layering .f {
z-index : 20;
}
10 2 Features of CSS Grid Module
Figure 2.6: This image shows the combatibility of different browsers with Grid [Can I use 2019].
This element is positioned "at z-index" 20, so it could have up to 20 different layers below it.
In former chapters, CSS Grid was discussed in general. How it developed over time from CSS Float
to more modern approaches. The workflow has been shown, different examples about how to use it
efficiently were presented and CSS Grid has been compared to older methods like Float and Flexbox.
Another part of this report was the discussion of Grid debugging for different Browsers, which should help
web developers working with the Grid. The last topic of this paper will be a discussion and comparison
of different Grid generating tools.
3.1 Introduction
Grid generators are a graphical tool for web developers. They are a convenient tool for creating a web
page layout with CSS Grid and offer an intuitive and interactive method for designing a basic Grid layout.
Instead of writing CSS and HTML code in separate files, such generators support the creation of a basic
layout graphically and translate it to HTML and CSS code. This way design decisions can be tested
and evaluated before applying to a real web page. Manipulating elements in these graphical tools is also
very easy and intuitive. When the result is acceptable, the corresponding CSS and HTML code can be
downloaded for further operational steps. After this short theoretical introduction, the next logical step
is to present some selected tools which illustrate the now discussed properties.
11
12 3 CSS Grid Generators
1 HTML:
2
3 <div class =" parent ">
4 <div class =" div1"> </div >
5 <div class =" div2"> </div >
6 <div class =" div3"> </div >
7 <div class =" div4"> </div >
8 <div class =" div5"> </div >
9 </div >
10
11
12 CSS:
13
14 . parent {
15 display : grid;
16 grid -template - columns : 1fr 4fr 1fr;
17 grid -template -rows: 1fr 4fr 1fr;
18 grid -column -gap: 0px;
19 grid -row -gap: 0px;
20 }
21 .div1 { grid -area: 2 / 2 / 3 / 3; }
22 .div2 { grid -area: 1 / 1 / 2 / 4; }
23 .div3 { grid -area: 3 / 1 / 4 / 4; }
24 .div4 { grid -area: 2 / 1 / 3 / 2; }
25 .div5 { grid -area: 2 / 3 / 3 / 4; }
Listing 3.1: Example code generated by CSS Grid Generator for corresponding layout shown in
Figure 3.1.
1 HTML:
2
3 <div class="grid - container ">
4 <div class=" Header "></div >
5 <div class="Main -Area">
6 <div class="Text -Area"></div >
7 <div class="Image -Area"></div >
8 </div >
9 <div class=" Sidebar "></div >
10 <div class=" Navigation "></div >
11 <div class=" Footer "></div >
12 </div >
13
14
15 CSS:
16
17 .grid - container {
18 display : grid;
19 grid -template - columns : 1fr 3fr 2fr 1fr;
20 grid -template -rows: 1fr 4fr 1fr;
21 grid -template -areas: " Header Header Header Header " " Sidebar Main -Area
Main -Area Navigation " " Footer Footer Footer Footer ";
22 }
23
24 . Header { grid -area: Header ; }
25
26 .Main -Area {
27 display : grid;
28 grid -template - columns : 1fr 1fr 1fr;
29 grid -template -rows: 1fr 1fr;
30 grid -template -areas: "Text -Area Text -Area Image -Area" "Text -Area Text -
Area Image -Area";
31 grid -area: Main -Area;
32 }
33
34 .Text -Area { grid -area: Text -Area; }
35
36 .Image -Area { grid -area: Image -Area; }
37
38 . Sidebar { grid -area: Sidebar ; }
39
40 . Navigation { grid -area: Navigation ; }
41
42 . Footer { grid -area: Footer ; }
Listing 3.2: Example code generated by Layoutit! for corresponding layout shown in Figure 3.2.
Vue Grid Generator by Masaya Kazama 15
1 HTML:
2
3 <div class=" container ">
4 <div class=" header ">header </div >
5 <div class=" navbar ">navbar </div >
6 <div class="left">left </div >
7 <div class="main">main </div >
8 <div class="right">right </div >
9 <div class=" footer ">footer </div >
10 </div >
11
12
13 CSS:
14
15 . container {
16 display : grid;
17 width: 100%;
18 height : 100%;
19 grid -template -areas: " header header header "
20 " navbar navbar navbar "
21 "left main right"
22 " footer footer footer ";
23 grid -template - columns : 1fr 4fr 1fr;
24 grid -template -rows: 1fr 1fr 4fr 1fr;
25 }
26 . container > div {
27 border : 1px dashed #888;
28 }
29
30 . header {
31 grid -area: header ;
32 }
33 . navbar {
34 grid -area: navbar ;
35 }
36 .left {
37 grid -area: left;
38 }
39 .main {
40 grid -area: main;
41 }
42 . right {
43 grid -area: right;
44 }
45 . footer {
46 grid -area: footer ;
47 }
Listing 3.3: Example code generated by Vue Grid Generator for corresponding layout shown in
Figure 3.3.
16 3 CSS Grid Generators
3.5 Conclusion
Starting with CSS Grid can be irritating when older approaches of CSS are still omnipresent. The
advantages of these new methods were discussed in this paper and Grid generators are a great introduction
to CSS Grid in general. Most of the generator tools are very similar in their usability and functionality,
they differ just in minor features. Some are more intuitive concerning their graphical representation,
some offer additional features as presets. Which one of the tools should be recommended depends on
the individual needs of a web developer. Overall CSS Grid generators are a good way to experiment with
CSS Grid they are a great tool for inexperienced users. However, their restrictive possibilities make these
tools irrelevant for veteran web developers and more experienced users.
Chapter 4
This chapter will take a look at inspector tools some browsers offer for working and debugging the Grids
built for a website, and their different features will be studied and compared.
To the date, only Mozilla Firefox and Google Chrome have some sort of feature in their inspectors
related to Grids, albeit there is also a Chrome extension for Grid inspection that will be studied too.
• Display area names, that would display the name of the areas over them if these were defined.
• Extend lines infinitely, property that extends the row and column lines to the end of the viewport in
order to visualize possible extensions for the Grid or alignment with other elements.
It is also important to notice that these display options will apply for all the currently selected Grids,
with no possibility to choose different configurations for each Grid.
Additionally, when only one Grid is selected for display, the inspector will also show a diagram of the
Grid, and hovering over a Grid area in it, the area from the actual Grid will be highlighted.
More importantly, any changes done to the CSS properties of the elements through the inspector will
also reflect in the Grid section of it. This allows the immediate visualization of modifications in the Grid.
The Grid panel was added in version 56 of Firefox, released in September 2017.
17
18 4 Grid Debugging Tools
Andrew, Rachel [2017]. The New CSS Layout. A Book Apart, 02 Oct 2017. ISBN 1-93-755768-5 (cited on
pages 1–2, 10).
Andrew, Rachel [2019]. Grid by Example - Everything you need to learn CSS Grid Layout. 01 Dec 2019.
https://gridbyexample.com/ (cited on pages 3–4, 6, 10).
Anton Savinskiy [2019]. Gridman - CSS Grid inspector. Ultra Fast! 01 Dec 2019. https : / / chrome .
google.com/webstore/detail/gridman-css-grid-inspecto/cmplbmppmfboedgkkelpkfgaakabpicn (cited on
page 19).
Can I use [2019]. CSS Grid Layout (level 1). 01 Dec 2019. https://caniuse.com/#feat=css-grid (cited
on page 10).
CSS-TRICKS [2016]. A Complete Guide to Grid. 06 Nov 2016. https://css-tricks.com/snippets/css/
complete-guide-grid/ (cited on page 2).
Drasner, Sarah [2019]. CSS Grid Generator. 01 Dec 2019. https://cssgrid- generator.netlify.com/
(cited on page 11).
Kazama, Masaya [2019]. CSS Grid Layout. 01 Dec 2019. https://github.com/miyaoka/grid-generator
(cited on page 13).
Leniolabs LLC [2019]. Layoutit. 01 Dec 2019. https://grid.layoutit.com/ (cited on page 13).
Matuzović, Manuel [2017]. Progressively Enhancing CSS Layout: From Floats To Flexbox To Grid.
Smashing Magazine. 24 Jul 2017. https://smashingmagazine.com/2017/07/enhancing- css- layout-
floats-flexbox-grid/ (cited on page 10).
Mozilla [2019]. Introduction to CSS Grid Layout - Firefox DevTools. 01 Dec 2019. https : / /
mozilladevelopers.github.io/playground/css-grid/03-firefox-devtools/ (cited on page 17).
W3School [2019]. CSS Layout - float and clear. 01 Dec 2019. https://css-tricks.com/snippets/css/
complete-guide-grid/ (cited on page 1).
21