{"id":255557,"date":"2018-02-20T20:54:38","date_gmt":"2018-02-20T19:54:38","guid":{"rendered":"https:\/\/www.elmastudio.de\/?p=255557\/"},"modified":"2018-02-21T03:29:41","modified_gmt":"2018-02-21T02:29:41","slug":"introduction-to-css-grid-layouts","status":"publish","type":"post","link":"https:\/\/www.elmastudio.de\/en\/introduction-to-css-grid-layouts\/","title":{"rendered":"Introduction to CSS Grid Layouts"},"content":{"rendered":"<p class=\"intro\"><strong>CSS Grid layouts are definitely<\/strong> one of the most exciting developments in CSS for years. It&#8217;s what all web designers and frontend developers have always dreamed of.<\/p>\n<p>Finally, we are able to convert our grid-based web designs directly into CSS without the help of javascript hacks or any kind of weird CSS technics. That sounds super exciting, doesn&#8217;t it? With CSS Grid, we can flexibly position any element of a web page just with CSS (such as our header, footer, sidebar or content blocks) exactly where we need it, regardless of its actual position in the markup. Here is a first overview of how this works.<\/p>\n<h3>How CSS Grid works<\/h3>\n<p>Until now we have done everything we could <em> (floating, flexbox, and javascript hacks)<\/em>, in order to be able to convert our responsive web designs into code. Often we have even reached our limits and certain layouts were simply not easily realized.<\/p>\n<p>All these efforts are finally coming to an end the introduction of CSS Grid layouts<em>(Yeah!)<\/em>. With CSS Grid we can now create grid columns and grid rows (vertical and horizontal lines) inside a container and then place our website elements completely flexible inside this grid.<\/p>\n<div class=\"wide-content\">\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-intro-4.jpg\" alt=\"\" width=\"2000\" height=\"975\" class=\"aligncenter size-full wp-image-255455\" srcset=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-intro-4.jpg 2000w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-intro-4-600x293.jpg 600w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-intro-4-1400x683.jpg 1400w\" sizes=\"auto, (max-width: 2000px) 100vw, 2000px\" \/>\n<\/div>\n<p>This new possibility is especially exciting for responsive web design, as we can now react much easier to different screen sizes and much easily adapted layouts with the help CSS Grid and a few added media queries.<\/p>\n<h3>Learn the CSS Grid Terminology<\/h3>\n<p>To use CSS Grid we need to learn some new terms, which I have summarized here in a small overview.<\/p>\n<h5>Grid container<\/h5>\n<p>Grid Container is the element inside the grid will be build. The CSS class to assign to your element is <code>display: grid<\/code>.<\/p>\n<h5>Grid item<\/h5>\n<p>Each element, that is directly inside the grid container is a grid item (so all elements that are nested inside the grid items don&#8217;t be come grid items themselves).<\/p>\n<h5>Grid line<\/h5>\n<p>There are two different types of grid lines. The vertical lines are called <em>&#8220;grid columns&#8221;<\/em> and the horizontal grid lines are called <em>&#8220;rows&#8221;<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-lines.jpg\" alt=\"\" width=\"1200\" height=\"880\" class=\"aligncenter size-full wp-image-255421\" srcset=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-lines.jpg 1200w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-lines-600x440.jpg 600w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-lines-580x425.jpg 580w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h5>Grid cell<\/h5>\n<p>Each cell of the grid is called grid cell. A grid cell is defined by two grid columns and two grid rows.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-cell.jpg\" alt=\"\" width=\"1200\" height=\"880\" class=\"aligncenter size-full wp-image-255417\" srcset=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-cell.jpg 1200w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-cell-600x440.jpg 600w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-cell-580x425.jpg 580w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h5>Grid area<\/h5>\n<p>Multiple cells together are called a grid area.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-area.jpg\" alt=\"\" width=\"1200\" height=\"880\" class=\"aligncenter size-full wp-image-255415\" srcset=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-area.jpg 1200w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-area-600x440.jpg 600w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-area-580x425.jpg 580w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h5>Grid track<\/h5>\n<p>A Grid track is the space between two column lines or two grid lines.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-track.jpg\" alt=\"\" width=\"1200\" height=\"860\" class=\"aligncenter size-full wp-image-255423\" srcset=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-track.jpg 1200w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-track-600x430.jpg 600w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-track-580x416.jpg 580w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h5>Grid gap<\/h5>\n<p>Grid columns and rows can have a grid gap, which is mostly called <em>gutter<\/em> in traditional design grids. It can have a fixed pixel value of e.g. 40px. It&#8217;s important to note that in CSS grid the gaps are not added to the first grid lines, so not at the outside of the grid, which is in contrary very common in traditional design grids.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-gaps-2.jpg\" alt=\"\" width=\"1200\" height=\"935\" class=\"aligncenter size-full wp-image-255419\" srcset=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-gaps-2.jpg 1200w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-gaps-2-600x468.jpg 600w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-gaps-2-580x452.jpg 580w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h5>The value fr<\/h5>\n<p><strong>fr<\/strong> <em>(which stands for fraction)<\/em> is a new value created for CSS grid. <code>grid-container: 1fr<\/code> means, that one fraction of the available space will be used.<\/p>\n<h5>Grid template column<\/h5>\n<p>So you can add your grid columns to your grid container like this:<\/p>\n<pre>\r\ngrid-template-columns: 2fr 1fr 1fr;\r\n<\/pre>\n<p>The layout result will look like this: <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-columns.jpg\" alt=\"\" width=\"1200\" height=\"880\" class=\"aligncenter size-full wp-image-255462\" srcset=\"https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-columns.jpg 1200w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-columns-600x440.jpg 600w, https:\/\/www.elmastudio.de\/wp-content\/uploads\/2018\/02\/css-grid-columns-580x425.jpg 580w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h5>Grid template rows<\/h5>\n<p>The default value for grid rows is <em>&#8220;auto&#8221;<\/em>. This means the content inside the grid row will define the height of the row. You can also add pixel or percentage values.<\/p>\n<pre>\r\ngrid-template-rows: 120px 25% auto;\r\n<\/pre>\n<h3>CSS Grid Browser Compatibility<\/h3>\n<p>Of course, at the moment there are still some older browsers that cause trouble and don&#8217;t offer CSS Grid support (which right now is mainly Internet Explorer 11).<\/p>\n<p>It&#8217;s best to check the <a href=\"https:\/\/caniuse.com\/#feat=css-grid\">caniuse.com<\/a> website on a regular basis, to see the current state of browser support for CSS grid. Windows Edge was still an issue a few months back, but the latest version now supports CSS grid.<\/p>\n<h3>Can we use CSS Grid now?<\/h3>\n<p>At Elmastudio we are currently working to integrate some CSS Grid functionality to our newest <a href=\"https:\/\/www.elmastudio.de\/en\/themes\/pukeko\/\">WordPress theme Pukeko<\/a>. In my opinion, a reasonable approach to the use of CSS Grid today is to recognize that not all browsers have to display a web design in the exact same way, and of course we are already all used to this since responsive web design is around.<\/p>\n<p>Morten Rand-Hendriksen explains this approach in his <a href=\"https:\/\/wordpress.tv\/2017\/06\/30\/morten-rand-hendriksen-css-grid-changes-everything-about-web-layouts\/\">CSS Grid Presentation<\/a> from WordCamp Europe 2017, where he describes his approach to use CSS grid today. He says we should realize that a website looks different in different browsers and on different screen sizes and we can also use this for CSS grids.<\/p>\n<p>He suggests <em> (and I also think this approach is the best solution at the moment)<\/em> creating a mobile-first web design without the help of CSS grid and offer this web design for older browsers that don&#8217;t support CSS grids as well.<\/p>\n<p>Then you can add to use CSS grid functionality for modern browsers and bigger screen sizes using <a href=\"https:\/\/www.smashingmagazine.com\/2018\/02\/media-queries-responsive-design-2018\/\">Media Queries<\/a>, in order to create your more complex, multi-column web design.<\/p>\n<p>This is the only way we, as web developers, can help to push the development of modern tools forward. By adopting new options as early as possible we can guarantee that they will become the new standard faster and that browser compatibility for CSS grids is soon an issue of the past.<\/p>\n<h4>Your Feedback<\/h4>\n<p>What are your thoughts on CSS Grid and what questions do you have? Are you using CSS Grid and maybe even built a live website already? Do you know other helpful resources on the topic and at what time do you think CSS Grids will be norm? <\/p>\n<p>Just write me a comment with your questions and your thoughts below, I&#8217;m looking forward to your feedback.<\/p>\n<h5>Further helpful resources to learn CSS Grid<\/h5>\n<p>&#8211; CSS Tricks detailed guide <a href=\"https:\/\/css-tricks.com\/snippets\/css\/complete-guide-grid\/\">A Complete Guide to Grid<\/a>.<br \/>\n&#8211; The A Book Apart book <a href=\"https:\/\/abookapart.com\/products\/the-new-css-layout\">A New CSS Layout<\/a> by Rachel Andrew.<br \/>\n&#8211; All  <a href=\"https:\/\/www.smashingmagazine.com\/category\/css-grid\">CSS grid related posts<\/a> on Smashing Magazine.<br \/>\n&#8211; Morten Rand-Hendriksens talk <a href=\"https:\/\/wordpress.tv\/2017\/06\/30\/morten-rand-hendriksen-css-grid-changes-everything-about-web-layouts\/\">CSS Grid Changes Everything (About Web Layouts)<\/a> at WordCamp Europe 2017.<br \/>\n&#8211; The <a href=\"https:\/\/www.youtube.com\/channel\/UC7TizprGknbDalbHplROtag\/videos\">Layout Land<\/a> Youtube channel with a number of super helpful videos explaining CSS Grid.<br \/>\n&#8211; The detailed resource list <a href=\"http:\/\/jensimmons.com\/post\/feb-27-2017\/learn-css-grid\">Learn CSS Grid<\/a> on Jen Simmons blog.<\/p>\n<p><strong>Reading time:<\/strong> about 4 minutes<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS Grid layouts are definitely one of the most exciting developments in CSS for years. It&#8217;s what all web designers and frontend developers have always dreamed of. Finally, we are able to convert our grid-based web designs directly into CSS without the help of javascript hacks or any kind of weird CSS technics. That sounds [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":255450,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1377,1397],"tags":[1179,1396,1400,1398,1330,1399],"class_list":["post-255557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-css","tag-css","tag-css-grid","tag-css-grid-layout","tag-grid-systems","tag-layouts","tag-learning"],"_links":{"self":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/posts\/255557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/comments?post=255557"}],"version-history":[{"count":0,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/posts\/255557\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/media\/255450"}],"wp:attachment":[{"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/media?parent=255557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/categories?post=255557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elmastudio.de\/en\/wp-json\/wp\/v2\/tags?post=255557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}