<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ grid layout - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ grid layout - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 26 Jun 2026 22:48:00 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/grid-layout/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ CSS Grid Layout ]]>
                </title>
                <description>
                    <![CDATA[ Grid Layout CSS Grid Layout, simply known as Grid, is a layout scheme that is the newest and the most powerful in CSS. It is supported by all major browsers and provides a way to position items on the page and move them around. It can automatically a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-grid-layout/</link>
                <guid isPermaLink="false">66c3484da124e2df05195f1f</guid>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ grid layout ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 31 Jan 2020 18:14:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9d3c740569d1a4ca36a6.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-grid-layout"><strong>Grid Layout</strong></h2>
<p>CSS Grid Layout, simply known as Grid, is a layout scheme that is the newest and the most powerful in CSS. It is <a target="_blank" href="https://caniuse.com/#feat=css-grid">supported by all major browsers</a> and provides a way to position items on the page and move them around.</p>
<p>It can automatically assign items to <em>areas</em>, size and resize them, take care of creating columns and rows based on a pattern you define, and doing all the calculations using the newly introduced <code>fr</code> unit.</p>
<h3 id="heading-why-grid"><strong>Why Grid?</strong></h3>
<ul>
<li>You can easily have a 12-column grid with one line of CSS. <code>grid-template-columns: repeat(12, 1fr)</code></li>
<li>Grid lets you move things in any direction. Unlike Flex, where you can move items either horizontally (<code>flex-direction: row</code>) or vertically (<code>flex-direction: column</code>) - not both at the same time, Grid lets you move any <em>grid item</em> to any predefined <em>grid area</em> on the page. The items you move do not have to be adjacent.</li>
<li>With CSS Grid, you can <strong>change the order of HTML elements using only CSS</strong>. Move something from top to the right, move elements that were in footer to the sidebar etc. Instead of moving the <code>&lt;div&gt;</code> from <code>&lt;footer&gt;</code> to <code>&lt;aside&gt;</code> in the HTML, you can just change it’s placement with <code>grid-area</code> in the CSS stylesheet.</li>
</ul>
<h3 id="heading-grid-vs-flex"><strong>Grid vs. Flex</strong></h3>
<ul>
<li>Flex is one-dimensional - either horizontal or vertical, while Grid is two-dimensional, meaning you can move elements in both horizontal and vertical planes</li>
<li>In Grid, we apply layout styles to the parent container and not the items. Flex on the other hand targets the flex item to set properties like <code>flex-basis</code>, <code>flex-grow</code>, and <code>flex-shrink</code></li>
<li>Grid and Flex are not mutually exclusive. You can use both on the same project.</li>
</ul>
<h3 id="heading-checking-browser-compatibility-with-supports"><strong>Checking browser compatibility with <code>@supports</code></strong></h3>
<p>Ideally, when you build a site, you’d design it with Grid and use Flex as a fallback. You can find out if your browser supports grid with the <code>@support</code> CSS rule (aka feature query). Here’s an example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid; <span class="hljs-comment">/* display grid by default */</span>
}

<span class="hljs-keyword">@supports</span> <span class="hljs-keyword">not</span> (<span class="hljs-attribute">display:</span> grid) { <span class="hljs-comment">/* if grid is not supported by the browser */</span>
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: flex; <span class="hljs-comment">/* display flex instead of grid */</span>
  }
}
</code></pre>
<h3 id="heading-getting-started"><strong>Getting Started</strong></h3>
<p>To make any element a grid, you need to assign its <code>display</code> property to <code>grid</code>, like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.conatiner</span> {
  <span class="hljs-attribute">display</span>: grid;
}
</code></pre>
<p>And that’s it. You just made your <code>.container</code> a grid. Every element inside the <code>.container</code> automatically becomes a grid item.</p>
<h3 id="heading-defining-templates"><strong>Defining templates</strong></h3>
<p>Rows and columns</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: 1<span class="hljs-selector-tag">fr</span> 1<span class="hljs-selector-tag">fr</span> 1<span class="hljs-selector-tag">fr</span> 1<span class="hljs-selector-tag">fr</span>;
<span class="hljs-selector-tag">grid-template-rows</span>: <span class="hljs-selector-tag">auto</span> 300<span class="hljs-selector-tag">px</span>;
</code></pre>
<p>Areas</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>: 
  "<span class="hljs-selector-tag">a</span> <span class="hljs-selector-tag">a</span> <span class="hljs-selector-tag">a</span> <span class="hljs-selector-tag">a</span>"
  "<span class="hljs-selector-tag">b</span> <span class="hljs-selector-tag">c</span> <span class="hljs-selector-tag">d</span> <span class="hljs-selector-tag">e</span>"
  "<span class="hljs-selector-tag">b</span> <span class="hljs-selector-tag">c</span> <span class="hljs-selector-tag">d</span> <span class="hljs-selector-tag">e</span>"
  "<span class="hljs-selector-tag">f</span> <span class="hljs-selector-tag">f</span> <span class="hljs-selector-tag">f</span> <span class="hljs-selector-tag">f</span>";
</code></pre>
<p>or</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>"
  "<span class="hljs-selector-tag">nav</span> <span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">sidebar</span>";
</code></pre>
<h3 id="heading-grid-areas"><strong>Grid Areas</strong></h3>
<p>Here’s some sample code on how to define and assign grid areas</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.site</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-areas</span>: <span class="hljs-comment">/* applied to grid container */</span>
    <span class="hljs-string">"head head"</span> <span class="hljs-comment">/* you're assigning cells to areas by giving the cells an area name */</span>
    <span class="hljs-string">"nav  main"</span> <span class="hljs-comment">/* how many values kind of depends on how many cells you have in the grid */</span>
    <span class="hljs-string">"nav  foot"</span>;
}

<span class="hljs-selector-class">.site</span> &gt; <span class="hljs-selector-tag">header</span> {
  <span class="hljs-attribute">grid-area</span>: head;
}

<span class="hljs-selector-class">.site</span> &gt; <span class="hljs-selector-tag">nav</span> {
  <span class="hljs-attribute">grid-area</span>: nav;
}

<span class="hljs-selector-class">.site</span> &gt; <span class="hljs-selector-tag">main</span> {
    <span class="hljs-attribute">grid-area</span>: main;
}

<span class="hljs-selector-class">.site</span> &gt; <span class="hljs-selector-tag">footer</span> {
    <span class="hljs-attribute">grid-area</span>: foot;
}
</code></pre>
<h3 id="heading-the-fr-unit"><strong>The <code>fr</code> unit</strong></h3>
<p>Grid introduces a new <code>fr</code> unit, which stands for <em>fraction</em>. The good thing about using the <code>fr</code> unit is that it takes care of calculations for you. Using <code>fr</code> avoids margin and padding issues. With <code>%</code> and <code>em</code> etc. it becomes a math equation when calculating <code>grid-gap</code>. If you used <code>fr</code> unit, it’ll automatically calculate both column and gutter sizes and adjust the size of the columns accordingly, plus there will be no bleeding gaps at the end either.</p>
<h3 id="heading-examples"><strong>Examples</strong></h3>
<h4 id="heading-changing-the-order-of-elements-based-on-screen-size"><strong>Changing the order of elements based on screen size</strong></h4>
<p>Let’s say you want to move the footer to the bottom on small screens and to the right on bigger screens, and there’s a bunch of other HTML elements in between the two.</p>
<p>The simple solution is to change the <code>grid-template-areas</code> based on the screen size. You can also <strong>change the number of columns and rows based on the screen size</strong>, too. This is a much cleaner and simpler alternative to Bootstrap’s Grid system (<code>col-xs-8 col-sm-6 col-md-4 col-lg-3</code>).</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.site</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">grid-template-areas</span>:
    <span class="hljs-string">"title title"</span>
    <span class="hljs-string">"main header"</span>
    <span class="hljs-string">"main sidebar"</span>
}

<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">34em</span>) { <span class="hljs-comment">/* If the screen is big enough, use a different template for grid areas */</span>
  <span class="hljs-selector-class">.site</span> {
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">2</span>fr <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
    <span class="hljs-attribute">grid-template-areas</span>:
      <span class="hljs-string">"title title title"</span>
      <span class="hljs-string">"main header header"</span>
      <span class="hljs-string">"main sidebar footer"</span>
  }
}
</code></pre>
<p>See the Pen <a target="_blank" href="https://codepen.io/aamnah/pen/RLVVoE/">CSS Grid by example - 2 (grid areas + grid gap)</a> by Aamnah Akram (<a target="_blank" href="https://codepen.io/aamnah">@aamnah</a>) on <a target="_blank" href="https://codepen.io/">CodePen</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How CSS Grid Changes the Way We Think About Structuring Our Content ]]>
                </title>
                <description>
                    <![CDATA[ By Kevin Powell CSS Grid changes how we can think about document structures Anyone who has even dabbled a little in creating websites knows that <div>s are an essential building block for controlling our layouts. HTML5 introduced new semantic element... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-grid-changes-how-we-can-think-about-structuring-our-content/</link>
                <guid isPermaLink="false">66d45f64b3016bf139028d50</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ grid layout ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 27 Sep 2019 15:56:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/08/marmoset-1567019547013.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Kevin Powell</p>
<h1 id="heading-css-grid-changes-how-we-can-think-about-document-structures">CSS Grid changes how we can think about document structures</h1>
<p>Anyone who has even dabbled a little in creating websites knows that <code>&lt;div&gt;</code>s are an essential building block for controlling our layouts.</p>
<p>HTML5 introduced new semantic elements to help, and while they are a fantastic addition to the language, they’re a little bit like the garnish on our <code>&lt;div&gt;</code> soup.</p>
<p><img src="https://paper-attachments.dropbox.com/s_81FBDAACE1729CFAB134F728BBD90343A8252037DFE26F8EB672CB6AB63DDAD8_1566407449963_div-soup.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>With grid, we no longer have to rely on <code>&lt;div&gt;</code>s to create the structure of our page, or even a more complex component. The structure is literally defined by the parent and not how the content is organized within in.</p>
<p>This means we can have nice, simple markup that sticks to the content itself without a reliance on organizing it through the use of <code>&lt;div&gt;</code>s. </p>
<h2 id="heading-grid-might-be-complicated-but-so-is-flexbox">Grid might be complicated, but so is flexbox</h2>
<p>I’ve heard a lot of people complain that grid is too complicated and that flexbox gets the job done. <strong>I’d argue that they are comfortable with flexbox and don’t want to bother learning grid because of that</strong>.</p>
<p>At the end of the day, Grid does introduce a boatload of new properties and values, so yes, there is a learning curve. But flexbox is plenty complicated as well. </p>
<p>Can you tell me the benefits of flex-basis over setting a width? Or really, how flexbox calculates the widths of flex items if we haven’t explicitly set them? </p>
<p>For example, if you showed the below example to someone who had never used flexbox, how do you explain the fact that it’s the same markup and the same CSS for both sets of columns? To make it even worse the second column in both has a width: 50%. Clearly that width of 50% isn’t really setting it to 50%.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/kevinpowell/embed/WNeRbjg" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>“Well, it starts off with flex items shrinking if there isn’t enough room, so even though we set the width to 50%, it doesn’t have the space, so it shrinks down to squeeze in because the other div requires more space. The 50% is more of its ideal size than what it will actually be. </p>
<p>“So in the top example, the first div’s content being so long is causing a problem because, as a flex item, by default, it wants to shrink to fit its content. In this case that item has a lot of content so…”</p>
<p><strong>So yes, flexbox is awesome and does a great job at creating layouts, but please don’t tell me that it’s simple</strong>. As soon as you get out of perfect examples, it’s often far from intuitive and sometimes it can be downright strange.</p>
<p>Grid is complicated in that there are <em>a lot</em> of new properties and values, but they gives us a lot more control than flexbox does. </p>
<p>In this article I’d like to look at how that extra layer of control helps simplify our markup and let us write less code, and that’s without even learning how to use a bunch of its fancy features.</p>
<h2 id="heading-the-limitations-of-flexbox">The limitations of flexbox</h2>
<p>Even if we take a simple component and build it with flexbox, because it only acts in 1-dimension at a time (the flex items are either rows or columns, they cannot be both), we’re left with a lot of divs to break things up into rows, which can then be split into columns.</p>
<p>For example, if we’re working on a card that looks like this:  </p>
<p><img src="https://paper-attachments.dropbox.com/s_81FBDAACE1729CFAB134F728BBD90343A8252037DFE26F8EB672CB6AB63DDAD8_1566998781330_Screen+Shot+2019-08-28+at+9.26.01+AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It’s not a complicated layout but we still need to organize our content in a pretty specific way to get it to work.  </p>
<p><img src="https://paper-attachments.dropbox.com/s_81FBDAACE1729CFAB134F728BBD90343A8252037DFE26F8EB672CB6AB63DDAD8_1566999564535_flex-overlay.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The yellow and orange boxes there are needed, so that when we place a display: flex; on the .card itself (the red box), it will create two columns. So to structure everything, we get markup that looks something like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"profile-sidebar"</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- profile image and social list here --&gt;</span> 
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"profile-body"</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- name, position, description here --&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>It’s not overly complicated by any means, and once you understand how flexbox works, it relatively straight forward.</p>
<p>When we put a <code>display: flex</code> on the <code>.card</code>, we'll get our two columns, and then we need to go into those and start styling them up. </p>
<p>Here is a working example with all the styling on it:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/kevinpowell/embed/rNBjaqV" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>The thing is, <strong>by having to create columns of content, we’re getting a little more complicated in the markup, and we’re also limiting ourselves</strong> as we’ve forced different pieces of content to be grouped together.</p>
<h2 id="heading-simplifying-everything-with-css-grid">Simplifying everything with CSS Grid</h2>
<p>Because grid is 2-dimensional, meaning that it allows us to create rows <em>and</em> columns at the same time, that means that our grid container (where we declare display: grid) has full control over the layout inside of it. </p>
<p>We used to <em>require</em> </p><div>s to do that, like in the above example with flexbox. With grid, we can remove the <div> s completely.<p></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.pravatar.cc/125?image=3"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"profile-img"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"social-list"</span>&gt;</span> ... <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"profile-name"</span>&gt;</span>Ramsey Harper<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"profile-position"</span>&gt;</span>Graphic Designer<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"profile-info"</span>&gt;</span>Lorem ipsum ...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>From a markup point-of-view, doesn’t this make a lot more sense?</p>
<p>We have a <code>.card</code> and then we place the content of that component in there. We don’t need to worry about breaking down how it will be structured, we just place the content that we need and move on from there.</p>
<h3 id="heading-structuring-the-layout">Structuring the layout</h3>
<p>Just like when we used flexbox for this, we still need to break the layout down, though because of how grid works, it looks a little different. </p>
<p>This is one place where people might argue grid is more complicated, but really I'm just drawing boxes around each peices of content, and then extending those lines.  </p>
<p><img src="https://paper-attachments.dropbox.com/s_81FBDAACE1729CFAB134F728BBD90343A8252037DFE26F8EB672CB6AB63DDAD8_1566999543180_grid-overlay.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>With flexbox, we created two divs that would act as our columns. When using grid, we instead set up the entire grid on the parent itself, and then we can tell the children where they belong on that grid.</p>
<p>To set up the grid, we can do something like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.card</span> {  
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">3</span>fr;
}
</code></pre>
<p>The <code>fr</code> unit is unique to grid, and is a fraction of the available space. Using it like this is very much like setting the two columns up in flexbox and giving them widths of <code>25%</code> and <code>75%</code> respectively. </p>
<h3 id="heading-placing-the-items-on-the-grid">Placing the items on the grid</h3>
<p>Maybe it’s because I used floats to create layouts for years, but it always feels like a little bit of magic when the different elements just end up where we want them to be! </p>
<p>We could use <code>grid-row</code> and <code>grid-column</code> on each element to place it where we want, but the more and more I use grid, the more I fall in love with taking the time to set up <code>grid-template-areas</code> and place my items into those areas. </p>
<p>The setup is a little bit longer, but the payoff really hits home when we make things responsive (we’ll get there soon).</p>
<p>So first, on the <code>.card</code> we need to setup the <code>grid-template-areas</code> and then we can assign all the children onto those areas:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.card</span> {
  ...
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">3</span>fr;
  <span class="hljs-attribute">grid-column-gap</span>: <span class="hljs-number">2em</span>;
  <span class="hljs-attribute">grid-template-areas</span>:
      <span class="hljs-string">"image name"</span>
      <span class="hljs-string">"image position"</span>
      <span class="hljs-string">"social description"</span>;
}


<span class="hljs-selector-class">.profile-name</span>     { <span class="hljs-attribute">grid-area</span>: name; }
<span class="hljs-selector-class">.profile-position</span> { <span class="hljs-attribute">grid-area</span>: position; }
<span class="hljs-selector-class">.profile-info</span>     { <span class="hljs-attribute">grid-area</span>: description; }
<span class="hljs-selector-class">.profile-img</span>      { <span class="hljs-attribute">grid-area</span>: image; }
<span class="hljs-selector-class">.social-list</span>      { <span class="hljs-attribute">grid-area</span>: social; }
</code></pre>
<p>Check it out here if you’d like to see it all in action:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/kevinpowell/embed/wvwdVyJ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-its-so-straight-forward">It’s so straight forward</h2>
<p>One of the things I love about using <code>grid-template-areas</code> are that it’s <em>so</em> easy for someone else to look at this code and immediately understand what is going on.</p>
<p>If someone shows you something that’s been setup using <code>grid-row</code> and <code>grid-column</code> using the numbers and spans, it’s easy enough to count things and figure out where they’ll end up. For simple layouts or for a quick span 3 here and there I think it’s fine to use them, <strong>but it’s so nice to look at <em>only</em> the CSS of a parent element and immediately understand what that entire layout is going to look like</strong>.</p>
<h3 id="heading-its-easier-to-know-the-actual-size-of-an-element-when-using-grid">It’s easier to know the actual size of an element when using grid</h3>
<p>In that very first example where we set the width of one of the flex items to 50%, it wasn’t really 50%. If you understand why that is, that’s great, but it can still be annoying at times. It’s easy enough to get around, but when using grid, it’s <em>much</em> less of an issue.</p>
<p>Because we are defining the complete layout, we’re also defining exactly how much space we want items to take up. </p>
<p>And sure, we get <code>minmax()</code> and <code>fr</code> which muddy the water a little as they allow for more flexible sizing (like we are using in our above example), but even then, we still have full control over that flexibity, and it’s all being controlled by the parent rather than having to set some things on the parent and others on the children.</p>
<h2 id="heading-limited-changes">Limited changes</h2>
<p>Looking at our above example, we can’t change that layout to look like this without changing the markup:</p>
<p><img src="https://paper-attachments.dropbox.com/s_81FBDAACE1729CFAB134F728BBD90343A8252037DFE26F8EB672CB6AB63DDAD8_1567000172227_Screen+Shot+2019-08-28+at+9.49.09+AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We’ve constrained ourselves because of how we had to group things together in <code>&lt;div&gt;</code>s. We had to use those <code>&lt;div&gt;</code>s in order to get the layout to work, but we’re stuck now. </p>
<p><strong>With the flat markup of our grid, anything is possible</strong>! And as an added bonus, because we set everything up using grid-template-areas, making these changes is super easy!</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.card</span> {
  <span class="hljs-comment">/* old layout 
  grid-template-areas:
      "image name"
      "image position"
      "social description"; */</span>

  <span class="hljs-comment">/* updated layout */</span>
  <span class="hljs-attribute">grid-template-areas</span>:
      <span class="hljs-string">"image name"</span>
      <span class="hljs-string">"image position"</span>
      <span class="hljs-string">"image social"</span>
      <span class="hljs-string">". description"</span>;
}
</code></pre>
<p>By playing with the <code>grid-template-areas</code> like this, it shifts the social icons to where we want them to be so quickly and easily (the <code>.</code> in the last part indicates and empty cell).</p>
<h2 id="heading-this-makes-life-so-easy-when-dealing-with-media-queries">This makes life so easy when dealing with media queries</h2>
<p>As I mentioned a few times now, one of the places where this pays off. We can completely control our layout with with our parent:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.card</span> {
  <span class="hljs-comment">/* setup for small screens */</span>
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">grid-column-gap</span>: <span class="hljs-number">2em</span>;
  <span class="hljs-attribute">grid-template-areas</span>: 
      <span class="hljs-string">"name"</span> 
      <span class="hljs-string">"image"</span> 
      <span class="hljs-string">"social"</span> 
      <span class="hljs-string">"position"</span> 
      <span class="hljs-string">"description"</span>;
}
<span class="hljs-selector-class">.profile-name</span>     {  <span class="hljs-attribute">grid-area</span>: name;}
<span class="hljs-selector-class">.profile-position</span> {  <span class="hljs-attribute">grid-area</span>: position; }
<span class="hljs-selector-class">.profile-info</span>     {  <span class="hljs-attribute">grid-area</span>: description; }
<span class="hljs-selector-class">.profile-img</span>      {  <span class="hljs-attribute">grid-area</span>: image; }
<span class="hljs-selector-class">.social-list</span>      {  <span class="hljs-attribute">grid-area</span>: social; } 


<span class="hljs-comment">/* rearanging the layout for large screens */</span>

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">600px</span>) {
  <span class="hljs-selector-class">.card</span> {
    <span class="hljs-attribute">text-align</span>: left;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">3</span>fr;
    <span class="hljs-attribute">grid-template-areas</span>: 
        <span class="hljs-string">"image name"</span> 
        <span class="hljs-string">"image position"</span> 
        <span class="hljs-string">"social description"</span>;
  }
  <span class="hljs-selector-class">.profile-name</span><span class="hljs-selector-pseudo">::after</span> {
    <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0</span>;
  }
}
</code></pre>
<p>The below pen has the entire thing styled up. Dive in there, play with the grid-areas, and see how easy it is to completely change the layout!</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/kevinpowell/embed/BaBRXvZ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-flexbox-still-has-its-place">Flexbox still has its place</h2>
<p>I do find myself turning to grid more and more, but I do think that flexbox still has its place. If I have a logo and navigation next to one another, it’s nice to simply do something like this and know that they are where I want them to be:<br><code>.header {  display: flex;  justify-content: space-between;}</code></p>
<p>The same for the <code>&lt;ul&gt;</code> we use for a navigation to simply get the items next to one another, or as you might have noticed in the card example we were looking at, it’s perfect for the <code>.social-list</code>.</p>
<p>For simple components where we don’t need a more complex layout, it works really well. But I find myself moving more and more toward grid, sometimes because of really needing it, other times because I want to use <code>minmax()</code> or use <code>fr</code> units.</p>
<p>But at the end of the day, I think the best thing about the grid is how we can simplify our markup so much. </p>
<p>We still need to use the humble <code>&lt;div&gt;</code>, but thanks to grid, we don’t have to rely on filling up our markup with them anymore.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>As great as flexbox is, it’s not simpler than grid. It does certain things really well, but grid allows us, when working on more complex layouts, to have much more control. That control is amplified when dealing with responsive design when making changes in media queries. </p>
<p>With flexbox, our one big change is changing the flex-direction. With grid, we can completely redesign a component quickly and easily.</p>
<p>There is a lot more to both flexbox and grid. Each one has its purpose, but if you feel like you’re not sure which one to pick, or if you’re struggling to figure out responsive design in general, I’ve recently released a course that dives into responsive design over on Scrimba called <strong><a target="_blank" href="https://scrimba.com/g/gresponsive">The Responsive Web Design Bootcamp</a></strong>. </p>
<p>It includes a deep dive into both Grid and Flexbox, as well as a full module devoted to how to start thinking responsively as well. In all, it has over 170 lessons, with 15+ hours of content, organized across 6 modules. So if you’d like to keep diving into the responsive world of CSS, you can <a target="_blank" href="https://scrimba.com/g/gresponsive">check it out here</a>.</p>
</div></div> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to create responsive tables with pure CSS using Grid Layout Module ]]>
                </title>
                <description>
                    <![CDATA[ By Shingo Nakayama TL;DR The most popular way to display a collection of similar data is to use tables, but HTML tables have the drawback of being difficult to make responsive. In this article, I use CSS Grid Layout Module and CSS Properties (and no ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/https-medium-com-nakayama-shingo-creating-responsive-tables-with-pure-css-using-the-grid-layout-module-8e0ea8f03e83/</link>
                <guid isPermaLink="false">66d460ee57503cc72873ded6</guid>
                
                    <category>
                        <![CDATA[ css properties ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Datatables ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ grid layout ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 26 Feb 2019 06:17:06 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*CthvMCprY75MLB_q8BygXg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Shingo Nakayama</p>
<h3 id="heading-tldr">TL;DR</h3>
<p>The most popular way to display a collection of similar data is to use tables, but HTML tables have the drawback of being difficult to make responsive.</p>
<p>In this article, I use CSS Grid Layout Module and CSS Properties (and no Javascript) to layout tables that wrap columns depending on screen width, which further changes to a card based on layout for small screens.</p>
<p>For the impatient, look at the following pen for a prototypical implementation.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/ShingoNakayama/embed/LMLeRZ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h3 id="heading-a-little-history-of-responsive-html-tables">A Little History of Responsive HTML Tables</h3>
<p>Responsive tables aren’t a new topic, and there are many solutions that have already been proposed. <a target="_blank" href="https://css-tricks.com/responsive-data-table-roundup/">“Responsive Table Data Roundup”</a> first published in 2012 by Chris Coyier, has things summarized very neatly (including a 2018 update).</p>
<p><a target="_blank" href="https://hashnode.com/post/really-responsive-tables-using-css3-flexbox-cijzbxd8n00pwvm53sl4l42cx">“Really Responsive Tables using CSS3 Flexbox”</a> by Vasan Subramanian shows an idea of wrapping columns, implemented with Flexbox.</p>
<p>Even though many interesting ideas have been proposed, libraries like <a target="_blank" href="https://getbootstrap.com/docs/4.0/content/tables/#responsive-tables">bootstrap</a> opt for horizontal scrolling for small screens.</p>
<p>As we now have CSS Grid, I think we could have a better common alternative to horizontal scrolling.</p>
<h3 id="heading-html-tables">HTML Tables</h3>
<p>Starting with the basics, a table in HTML is a layout format for displaying collections of items through a matrix of rows and columns. Items are laid out in rows, with the same data attributes in the same columns, with the rows often sorted with one or more sortable attributes. The format gives you a birds-eye view to quickly grasp and examine large quantities of data.</p>
<p>For example, here’s a hypothetical table of purchase order details, that you may see in a purchasing application.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*B78yFFUVc1X8uEp_gVLcNw.png" alt="Image" width="800" height="57" loading="lazy">
<em>Table of purchase order details</em></p>
<p>An item, in this case, is a purchase order detail, that has attributes such as part number, part description, etc.</p>
<p>When using HTML tables, the layout of the data is hardcoded as rows and columns (e.g. <code>&lt;tr&gt;</code> and <code>&lt;td&gt;</code>). This may be sufficient for usage by a screen that fits the whole table width, but in reality, this does not apply for the myriad of devices that exist today. In terms of hacks, you can alter the display property of tables and use any layout you can do with CSS in general, but that doesn’t seem semantically correct.</p>
<h3 id="heading-tables-redefined-collection-of-items">Tables Redefined (= Collection of Items)</h3>
<p>Let’s start by redefining how table data should be expressed in HTML.</p>
<p>As stated earlier, since table data is essentially an ordered collection of items, it seems natural to use ordered lists. Also, since tables are often used to supplement textual descriptions, it seems natural to enclose this in a section, but this would depend on the context of how the table data is being used.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">ol</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- The first list item is the header of the table --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>#<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
   <span class="hljs-comment">&lt;!-- Enclose semantically similar attributes as a div hierarchy --&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Part Number<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Part Description<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
   <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
   ...
  <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- The rest of the items in the list are the actual data --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
   <span class="hljs-comment">&lt;!-- Group part related information--&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>100-10001<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Description of part<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
   <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  ...
  <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
 ...
 <span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>Vanilla <code>&lt;div&gt;</code>'s are used to express item attributes since HTML5 does not define an appropriate tag for this. The key here is to express semantically similar attributes as a hierarchy of <code>&lt;div&gt;</code>'s. This structure will be used when defining how the data should be laid out. I will come back to this in the next section on the topic of styling.</p>
<p>As for the actual data inside the <code>&lt;div&gt;</code> element, the first item in the list is the header, and the rest of the items are the actual data.</p>
<p>Now, it’s time to start talking about styling the items with CSS Grid.</p>
<h3 id="heading-styling-item-collections">Styling Item Collections</h3>
<p>The basic idea here is to display all attributes of the item as a normal table, display width permitting. This layout has the luxury of being able to see as many items (rows) as possible.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*6sZipUcqB3hru4Q5r0kORw.png" alt="Image" width="800" height="48" loading="lazy">
<em>Full Table</em></p>
<p>When the width of the display becomes narrower, some attributes are stacked vertically, in order to save horizontal space. The choice of stacking attributes should be based on:</p>
<ol>
<li>Do the attributes make sense when stacked vertically? and,</li>
<li>When stacked vertically, does it save horizontal space?</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*llLsnXzdnBBfMRPqoKNBmw.png" alt="Image" width="800" height="110" loading="lazy">
<em>Wrapping Table 1. Start by wrapping columns that need little width, and give the other columns space</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*DdQ-n4VzeGU1EzhRKdHj8w.png" alt="Image" width="800" height="116" loading="lazy">
<em>Wrapping Table 2. Wrap “Part Description”, to be able to see the description</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ys0ukWXXtbWhVyXTD9E0Zw.png" alt="Image" width="800" height="145" loading="lazy">
<em>Wrapping Table 3. Further wrap “Vendor Name”</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*-ik1zA0LDXzWib7Ux-4EpQ.png" alt="Image" width="800" height="267" loading="lazy">
<em>Wrapping Table 4. Wrap vendor related information under part related information</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*sEvQQjZoux7PEii3JQpCRg.png" alt="Image" width="747" height="353" loading="lazy">
<em>Wrapping Table 5. Fully wrapped</em></p>
<p>When the width further shrinks to the size of a mobile device, each item is displayed as a card. This layout has redundancy because the attribute names are repeatedly displayed on each card, and has the least glanceability, but does not compromise usability (e.g. horizontal scrolling, super small text, etc).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*jI0hhzrpYpjbO3-fGh8IWA.png" alt="Image" width="695" height="485" loading="lazy">
<em>Two Column Card Layout</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*XCCcicUngRBcBaKyETC4vg.png" alt="Image" width="445" height="722" loading="lazy">
<em>One Column Card Layout</em></p>
<p>Now let’s dive into the details.</p>
<h4 id="heading-styling-step-1-full-table">Styling Step 1: Full Table</h4>
<p>Here’s a visual summary of how things will be implemented with CSS Grid.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*uA9PfcQ9JCzY54mH7p_v-A.png" alt="Image" width="755" height="344" loading="lazy">
<em>Grid containers</em></p>
<p>In order to make columns wrap, multiple grid containers are defined as a hierarchy. The red box is a grid container for each row, and the blue box is a container for each column group that wraps.</p>
<p>Let’ s start by setting the list as a grid container by defining a class called <code>.item-container</code> and applying it to the <code>&lt;li&gt;</code>(the red box).</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.item-container</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">2em</span> <span class="hljs-number">2em</span> <span class="hljs-number">10</span>fr <span class="hljs-number">2</span>fr <span class="hljs-number">2</span>fr <span class="hljs-number">2</span>fr <span class="hljs-number">2</span>fr <span class="hljs-number">5em</span> <span class="hljs-number">5em</span>;
}
</code></pre>
<p>The number of explicit columns specified with <code>grid-template-columns</code> is nine, which is the number of top-level <code>&lt;div&gt;</code>'s, directly  under <code>&lt;li&gt;</code>.</p>
<p>The column’s width is defined in relative length to make the columns wrap. The actual fraction has to be fine-tuned, based on the content.</p>
<p>The columns that don’t wrap are defined in absolute length to maximize width usage for the wrapping columns. In the purchase order details example, the second column is a two-digit Id, so I set the width to double that size of 2 m’s.</p>
<p>Next, we define another grid container called <code>.attribute-container</code> and apply it on all intermediate <code>&lt;div&gt;</code>’s under the list (the blue box).</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.attribute-container</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fit, minmax(var(--column-width-min), <span class="hljs-number">1</span>fr));
    }
</code></pre>
<p>The minimum column width for all grid items under <code>.attribute-container</code> is specified with a CSS variable called <code>--column-width-min</code>(more on this later) using the <code>minmax</code> function, with the maximum set to take the rest of the space (e.g. one fraction). Since <code>grid-template-columns</code> are <code>repeat</code>ed, available horizontal space will be split into the maximum number of columns that could take at least <code>--column-width-min</code>, and the rest of the columns would go to the next line. The column’s width will be stretched if there is excess horizontal space because the <code>repeat</code> is <code>auto-fit</code>ed.</p>
<h4 id="heading-styling-step-2-wrapping-table">Styling Step 2: Wrapping Table</h4>
<p>Next, <code>--column-width-min</code> needs to be specified independently for each column in order to wrap. Just to be clear, the variables need to be specified in order for the full table to render properly as well. To do this, a class is set for each <code>.attribute-container</code>, and a different <code>--column-width-min</code> is specified for each class scope.</p>
<p>Let’s take a look at the HTML where <code>.part-id</code> is applied,</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute-container part-id"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Part Number<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Part Description<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>and the CSS:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.part-id</span> {
    <span class="hljs-attribute">--column-width-min</span>: <span class="hljs-number">10em</span>;
}
</code></pre>
<p>This specific grid container will have two columns, as long as the available width is wider than 10em for each grid item (e.g. the grid container is wider than 20em). Once the grid container’s width becomes narrower than 20em, the second grid item will go to the next row.</p>
<p>When we combine CSS properties like this, we need only one grid container <code>.attribute-container</code>, with the details changing where the class is applied.</p>
<p>We can further nest <code>.attribute-container</code>s, to have multiple levels of wrapping with different widths, as in the following exert.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute-container part-information"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute-container part-id"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute"</span> <span class="hljs-attr">data-name</span>=<span class="hljs-string">"Part Number"</span>&gt;</span>Part Number<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute"</span> <span class="hljs-attr">data-name</span>=<span class="hljs-string">"Part Description"</span>&gt;</span>Part Description
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute-container vendor-information"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute"</span>&gt;</span>Vendor Number<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribute"</span>&gt;</span>Vendor Name<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
.part-information {
    --column-width-min: 10em;
}
.part-id {
    --column-width-min: 10em;
}
.vendor-information {
    --column-width-min: 8em;
}
</code></pre>
<p>All of the above is enclosed in the following media query. The actual breakpoint should be selected based on the width necessary when your table is wrapped to the extreme.</p>
<pre><code>@media screen and (min-width: <span class="hljs-number">737</span>px) {
...
}
</code></pre><h4 id="heading-styling-step-three-card-layout">Styling Step Three: Card Layout</h4>
<p>The card layout will look like a typical form with attribute names in the first column and attribute values in the second column.</p>
<p>To do this, a class called <code>.attribute</code> is defined and applied to all leaf <code>&lt;div&gt;</code> tags under the <code>&lt;li&gt;</code>.</p>
<pre><code class="lang-js">.attribute {
    <span class="hljs-attr">display</span>: grid;
    grid-template-columns: minmax(<span class="hljs-number">9</span>em, <span class="hljs-number">30</span>%) <span class="hljs-number">1</span>fr;
}
</code></pre>
<p>The attribute names are taken from a custom attribute of the leaf  <code>&lt;div&gt;</code> called <code>data-name</code>, for example <code>&lt;div class=”attribute” data-name="Part Number"&gt;</code>, and a pseudo-element is created. The pseudo-element will be subject to the grid container’s layout.</p>
<pre><code class="lang-js">.attribute::before {
    <span class="hljs-attr">content</span>: attr(data-name);
}
</code></pre>
<p>The first item in the list is the header and does not need to be displayed.</p>
<pre><code class="lang-js"><span class="hljs-comment">/* Don't display the first item, since it is used to display the header for tabular layouts*/</span>
.collection-container&gt;li:first-child {
    <span class="hljs-attr">display</span>: none;
}
</code></pre>
<p>And finally, the cards are laid out in one column for mobile devices, but two for screens with a little bit more width, but not enough for displaying a table.</p>
<pre><code><span class="hljs-comment">/* 2 Column Card Layout */</span>
@media screen and (max-width: <span class="hljs-number">736</span>px) {
    .collection-container {
        <span class="hljs-attr">display</span>: grid;
        grid-template-columns: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
        grid-gap: <span class="hljs-number">20</span>px;
    }
...
}
<span class="hljs-comment">/* 1 Column Card Layout */</span>
@media screen and (max-width:<span class="hljs-number">580</span>px) {
    .collection-container {
        <span class="hljs-attr">display</span>: grid;
        grid-template-columns: <span class="hljs-number">1</span>fr;
    }
}
</code></pre><h3 id="heading-finishing-notes">Finishing Notes</h3>
<p>Accessibility is an area that wasn’t considered at all and may have some space for improvement.</p>
<p>If you have any ideas or second thoughts, please feel free to comment!</p>
<p>And of course, thanks for reading.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 11 Things I Learned Reading the CSS Grid Specification ]]>
                </title>
                <description>
                    <![CDATA[ By Emmanuel Ohans June 11, 2017, I decided to read the CSS Grid spec. The Spec was a little bit technical, but it was by far the most enjoyed specification I had ever read. If you’re a more advanced developer, bookmark it for future references. So, w... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/11-things-i-learned-reading-the-css-grid-specification-fb3983aa5e0/</link>
                <guid isPermaLink="false">66d45e3d8812486a37369c91</guid>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ grid layout ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 10 Dec 2017 21:24:45 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*_bY8jlwMIB_Mr1XJ_aJ9Ug.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Emmanuel Ohans</p>
<p>June 11, 2017, I decided to read the CSS Grid spec.</p>
<p>The Spec was a little bit technical, but it was by far the most enjoyed specification I had ever read. If you’re a more advanced developer, <a target="_blank" href="https://www.w3.org/TR/css-grid-1/">bookmark</a> it for future references.</p>
<h3 id="heading-so-will-this-be-helpful">So, will this be helpful?</h3>
<p>I believe the difference between good and great engineers, is that the latter take their time to understand what really goes on under the hood. They learn how things work, instead of learning by “copy and paste.”</p>
<p>So, do you want to be a great developer?</p>
<p>Hell, yeah. Or, you wouldn’t be reading this article.</p>
<h3 id="heading-what-youll-learn">What you’ll learn</h3>
<p>While reading the spec, I learned some very subtle, but profound details.</p>
<p>In this article, I will share them with you.</p>
<h3 id="heading-1-the-css-grid-is-declarative">1. The CSS Grid is declarative</h3>
<p>Declarative APIs are so sweet to work with. Think <a target="_blank" href="http://reactjs.org">ReactJS</a>?</p>
<p>As websites evolved from simple documents into complex, interactive applications, web layouts became difficult to compose. So difficult, they were my nightmare.</p>
<p>This is exactly the problem CSS Grid has come to solve today.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*42E2QtypEfccqXqb640jMw.png" alt="Image" width="800" height="633" loading="lazy">
<em>From the spec.</em></p>
<p>The CSS Grid takes away the painful process of crafting intelligent layouts and replaces it with a beautiful set of declarative rules that make the process near effortless.</p>
<p>These are good times in the history of CSS.</p>
<h3 id="heading-2-the-fractional-unit-does-not-always-produce-equally-spaced-rows-and-columns">2. The fractional unit does not always produce equally spaced rows and columns</h3>
<p>One of the first things everyone learns and gets to love about the CSS Grid is the <a target="_blank" href="https://medium.com/flexbox-and-grids/the-css-fractional-unit-fr-in-approachable-plain-language-fdc47bd387f7">fractional unit</a>. Even a duck can get away with it.</p>
<p>The fractional unit takes away the pain of calculating percentages. It is a delight to work with.</p>
<p>Most people teach that the fractional unit (fr) yields equally spaced columns or rows.</p>
<p>For example, a declaration like <code>1fr 1fr 1fr</code> is expected to give you columns or rows of equal spacing. See the illustration below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*1TWb0kZ4nn6uvykRLMGtOw.png" alt="Image" width="800" height="449" loading="lazy">
<em>Equally spaced columns created by the fractional unit.</em></p>
<p>Sadly, this is NOT always true. Poor duck.</p>
<p>The following is from the spec:</p>
<blockquote>
<p>The <code>fr</code> unit fills up the available space BUT it is NEVER smaller than the minimum size of the grid container or the content of the row or column.</p>
</blockquote>
<p>Essentially, If you have an image, <code>img</code> or any grid item, with a <code>min-width</code> or <code>min-height</code> declaration, you can have unexpected results with the fractional unit.</p>
<p>After quacking around like a wet scared duck, I spent a lot of time experimenting with the fractional unit. I wrote an <a target="_blank" href="https://medium.com/flexbox-and-grids/what-you-didnt-know-about-the-css-fractional-unit-580bd62647e8">article</a> on my findings.</p>
<h3 id="heading-3-you-dont-really-know-how-grids-are-sized-or-do-you">3. You don’t really know how Grids are sized. Or, do you?</h3>
<p>A CSS grid definition always begins in the lines of this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">grid</span>
</code></pre>
<p>Often times, it is followed by the <code>row</code> and <code>column</code> definitions. Something like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-rows</span>: 10<span class="hljs-selector-tag">px</span> 1<span class="hljs-selector-tag">fr</span> 3<span class="hljs-selector-tag">fr</span>
<span class="hljs-selector-tag">grid-template-columns</span>: 1<span class="hljs-selector-tag">fr</span>
</code></pre>
<p>And finally, you are likely to place the grid items with whatever technique suits you.</p>
<p>Since there are lots of ways to place grid items, I’ll skip the required code for brevity.</p>
<p>So, here’s the problem.</p>
<p>Under the hood, you must assume that the size of the grid rows and columns are first computed before the items are placed. Right?</p>
<p>Well, it appears that the truth is the complete opposite.</p>
<p>How weird.</p>
<p>The following is from the spec:</p>
<blockquote>
<p><em>2.3. Sizing the Grid</em>  </p>
<p><strong><em>Once the grid items have been placed</em></strong><em>, the sizes of the grid tracks (rows and columns) are calculated, accounting for the sizes of their contents and/or available space as specified in the grid definition.</em></p>
</blockquote>
<p>Note the progression.</p>
<ol>
<li>The grid items are placed.</li>
<li>The sizes of the grid tracks are calculated</li>
</ol>
<p>You’re likely to have questions around this. So, I’ll try to resolve those concerns of yours.</p>
<p>Firstly, note that every grid item is assigned a <code>grid-area</code> . The grid items are then sized within this area. So, how exactly are the grid items placed without already calculating the size of the tracks?</p>
<p>If you take a look at the <a target="_blank" href="https://www.w3.org/TR/css-grid-1/#placement">Placing Grid items</a> section of the spec, you’ll find a clue.</p>
<p>A lot is taken into consideration when sizing grids, and that largely includes the size of the grid items.</p>
<p>Sizing grids may be based on the following:</p>
<ul>
<li>A fixed sizing function (<code>[length](https://www.w3.org/TR/css3-values/#length-value)</code> or resolveable <code>[percentage](https://www.w3.org/TR/css3-values/#percentage-value)</code>).</li>
<li>An intrinsic sizing function (<code>[min-content](https://www.w3.org/TR/css-grid-1/#valdef-grid-template-columns-min-content)</code>, <code>[max-content](https://www.w3.org/TR/css-grid-1/#valdef-grid-template-columns-max-content)</code>, <code>[auto](https://www.w3.org/TR/css-grid-1/#valdef-grid-template-columns-auto)</code>, <code>[fit-content()](https://www.w3.org/TR/css-grid-1/#valdef-grid-template-columns-fit-content)</code>), or</li>
<li>A flexible sizing function (<code>[flex](https://www.w3.org/TR/css-grid-1/#typedef-flex)</code>).</li>
</ul>
<p>What I believe happens under the hood is, the grid items are placed.</p>
<p>That is, the containing block for the item is determined, the sizing function for the item is then determined. This in turn influences the size of the grid tracks.</p>
<p>You see?</p>
<p>Not what you initially thought.</p>
<h3 id="heading-4-by-default-grid-items-are-stretched-to-fit-their-grid-area-except-in-certain-cases">4. By default, grid items are stretched to fit their grid area — except in certain cases</h3>
<p>Without your intervention, grid items will always stretch to fit their grid area.</p>
<p>So, if you had a declaration like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>: '<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>'
                     '<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">main</span>  <span class="hljs-selector-tag">main</span>'
                     '<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span>'
</code></pre>
<p>And you had <code>divs</code> assigned to the specific grid areas, like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.div1</span> {
   <span class="hljs-attribute">grid-area</span>: header
}
<span class="hljs-selector-class">.div2</span> {
   <span class="hljs-attribute">grid-area</span>: sidebar
}
<span class="hljs-selector-class">.div3</span> {
   <span class="hljs-attribute">grid-area</span>: main
}
<span class="hljs-selector-class">.div4</span> {
   <span class="hljs-attribute">grid-area</span>: footer
}
</code></pre>
<p>You don’t need to declare the <code>width</code> and <code>height</code> of the <code>divs</code> above to <code>100%</code></p>
<p>They will automatically stretch to fill their respective areas.</p>
<p>Now, here’s the catch.</p>
<p>This behavior is inconsistent with Images.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/OhansEmmanuel/status/937989769199538177?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E937989769199538177&amp;ref_url=https%3A%2F%2Fmedium.com%2Fmedia%2F78db622c8451a1502c78fa03c8da0d71%3FpostId%3Dfb3983aa5e0"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>As pointed out by <a target="_blank" href="https://www.freecodecamp.org/news/11-things-i-learned-reading-the-css-grid-specification-fb3983aa5e0/undefined">Rachel Andrew</a>, the <a target="_blank" href="https://www.w3.org/TR/css-grid-1/#grid-item-sizing">spec</a> goes on to say this behavior is different for grid items with an <code>intrinsic aspect ratio</code>.</p>
<p>Don’t let the big words scare you. It ain’t no demogorgon.</p>
<p>An image is by default an <code>inline-block</code> element, but they also have specific dimensions. They have dimensions naturally associated with them. An image could be <code>400px</code> by <code>600px</code> wide, or any given dimensions at all.</p>
<p>But, regular block elements such as <code>divs</code> , have no intrinsic dimensions. That is, they do not have dimensions that naturally belong to them.</p>
<p>So, while grid items with NO intrinsic dimensions will stretch to fit their grid area, this is not true for grid items having an intrinsic dimension e.g images.</p>
<h3 id="heading-5-do-you-really-know-what-a-grid-item-is">5. Do you really know what a Grid Item is?</h3>
<p>Consider the code block below:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display: grid"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>block<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>float<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    I am a random Text 

    <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
        item 4
    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>In the code block above, can you spot the grid items?</p>
<p>How many grid items are in the code block, 3 or 4?</p>
<p>I failed this question blatantly.</p>
<p>Note that the text <code>I am a random text</code> isn’t wrapped by any <code>html</code> tags.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Y-ugQCjXh2JQTK9nnZm3ag.png" alt="Image" width="800" height="202" loading="lazy">
<em>which is it?</em></p>
<p>So, what’s your answer?</p>
<p>Well, if you answered 3, you’re wrong. Haha, got ya!</p>
<p>According to the spec, <strong>an anonymous grid item</strong> is wrapped around each run of text within a grid.</p>
<p>Yes, that means <code>I am a random text</code> is also a grid item.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display: grid"</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>block<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>float<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- the text below is a grid item --&gt;</span>
    I am a random Text 

    <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
        item 4
    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Yeah, the answer is 4. We’ve got 3 explicit grid items and 1 anonymous grid item!</p>
<p>Got that?</p>
<h3 id="heading-6-the-margins-of-adjacent-grid-items-do-not-collapse">6. The margins of adjacent grid items do not collapse.</h3>
<p>There are big differences between block elements and grid containers.</p>
<p>What I mean is, an element with <code>display: block</code> and another with <code>display: grid</code> have a lot of fundamental differences.</p>
<p>The difference I am choosing to discuss here is got to do with collapsible margins.</p>
<p>One of first things you learn with CSS is the concept of collapsible margins. I don’t want to spend a lot of time explaining what collapsible margins mean. If you bring it up in the comments, I will.</p>
<p>So, back to grids.</p>
<p>With every grid item, the margins are never collapsed.</p>
<p>Well, this is understandable. Let me show you why.</p>
<p>Adjacent grid items are independently contained within the containing block formed by their grid areas.</p>
<p>What that complex paragraph above means is this. Each grid item lives and breathes within a <code>grid-area</code></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*mJYB7D_bzUJOHueTKZM0IQ.png" alt="Image" width="800" height="352" loading="lazy">
<em>Grid items are placed within their respective grid areas. They stay in their own undisturbed territories. They are unaffected by collapsible margins. How cool.</em></p>
<p>So, technically, you may say the grid item isn’t an immediate neighbor of the other grid items. But is contained within an uninterrupted closed territory — the grid area.</p>
<p>If you’re curious what other differences exist between block elements and grid elements, I wrote an interesting <a target="_blank" href="https://medium.com/flexbox-and-grids/css-grid-layout-3-vital-differences-between-grid-containers-block-containers-6f3c39cf3bba">article</a> on the subject.</p>
<h3 id="heading-7-auto-fill-and-auto-fit-whats-the-difference">7. <code>auto-fill</code> and <code>auto-fit. What's the difference?</code></h3>
<p>While <code>auto-fill</code> and <code>auto-fit</code> look like the same functions they are different in a way.</p>
<p>They are similar in the sense that they allow for automatically creating grid tracks that fill up the grid container in some way.</p>
<p>For example, the following code will create as many <code>200px</code> columns as will fit into the window width. If there is any remaining space, it will be distributed among the <code>200px</code> columns.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">200px</span>, <span class="hljs-number">1</span>fr));
}
</code></pre>
<p>What’s the difference?</p>
<p><code>auto-fill</code> will create tracks even if there's no grid item to fill it up. <code>auto-fit</code> will not do this. It will deflate empty tracks to zero.</p>
<p>That's all.</p>
<h3 id="heading-8-in-the-grid-template-areas-definition-the-number-of-words-in-a-string-must-be-equal">8. In the grid-template-areas definition, the number of words in a string MUST be equal.</h3>
<p>You remember the weird looking <code>grid-template-areas</code> values that look like a map?</p>
<p>Well, it appears it can mess things up real quick.</p>
<p>In a <code>grid-template-areas</code> declaration, all strings must have the same number of columns, or else the declaration is invalid.</p>
<p>For example:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* this is valid */</span>

<span class="hljs-selector-tag">grid-template-areas</span>: "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">sidebar</span>"
                     "<span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">sidebar</span>"
                     "<span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">sidebar</span>"

<span class="hljs-comment">/* this is WRONG */</span>

<span class="hljs-selector-tag">grid-template-areas</span>: "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">sidebar</span>"
                     "<span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">sidebar</span>"
                     "<span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>     <span class="hljs-selector-tag">sidebar</span>"
</code></pre>
<p>The number of word in the strings, must be equal.</p>
<h3 id="heading-9-avoid-using-percentages-in-paddings-or-margins-on-grid-items-entirely">9. Avoid using percentages in paddings or margins on grid items entirely</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*KsdfpVZap5kke83AI042CA.png" alt="Image" width="800" height="80" loading="lazy">
_[From the CSS Grid Spec](https://www.w3.org/TR/css-grid-1/#item-margins" rel="noopener" target="<em>blank" title=")</em></p>
<p>The reason behind this is simple. At the time of this writing, you will get different behavior in different browsers.</p>
<p>According to the spec, the percentage may be resolved either against the <code>width</code> of the element alone, or <code>left</code>/<code>right</code> margins against the <code>width</code> while <code>top</code>/<code>bottom</code> are resolved against the <code>height</code></p>
<p>In order to have a consistent rendering across most browsers, avoid using percentages in paddings or margins of grid items.</p>
<p>More importantly, there are already a few confusing bits with the CSS Grid. Don’t shoot yourself in the foot with percentages paddings or margins in grid items.</p>
<h3 id="heading-10-hows-the-size-of-the-explicit-grid-resolved-when-theres-a-conflict">10. How’s the size of the explicit grid resolved when there’s a conflict?</h3>
<p>Assume that you have a grid declaration like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>: "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">sidebar</span>"
                     "<span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">sidebar</span>"
                     "<span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">main</span>   <span class="hljs-selector-tag">sidebar</span>"
</code></pre>
<p>In the code block above, you have 4 columns and 3 rows.</p>
<p>What if you also did this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: <span class="hljs-selector-tag">repeat</span>(5, 1<span class="hljs-selector-tag">fr</span>) 
<span class="hljs-selector-tag">grid-template-rows</span>: <span class="hljs-selector-tag">repeat</span>(4, 1<span class="hljs-selector-tag">fr</span>)
</code></pre>
<p>Now you have more columns and rows. 5 columns, and 4 rows.</p>
<p>You got that?</p>
<p>There’s now a conflict in the declarations. So, how is this resolved?</p>
<p>According to the spec, the size of the explicit grid is determined by the larger of the number of <code>rows/columns</code> defined by <code>grid-template-areas</code> and the number of <code>rows/columns</code> sized by <code>grid-template-rows/grid-template-columns</code>.</p>
<p>The spec may seem like it complicated a simple thing. In plain language, what that means is, the declaration with the larger number of <code>rows</code> or <code>columns</code> wins.</p>
<p>In the example above, the grid will take up 5 columns, and 4 rows NOT 4 columns and 3 rows.</p>
<p><strong>*EDIT:</strong> The <code>grid-template-areas</code> property is used to place grid items on a grid. So, why should we have a conflict in grid definition? Aren’t grids supposed to be defined with just the <code>grid-template-columns</code> and <code>grid-template-rows</code> properties? I answer this in the comment section. Check it out.</p>
<h3 id="heading-11-the-size-of-the-grid-is-not-purely-the-sum-of-the-track-sizes">11. The size of the grid is not purely the sum of the track sizes</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*0NJt-xbXYw1C5SQHCS1SUg.png" alt="Image" width="800" height="454" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Axq_JnjdpJp2RUg6z5iaIw.png" alt="Image" width="800" height="454" loading="lazy">
<em>Grid tracks refer to the distance between grid lines.</em></p>
<p>While this is simple, it is worth mentioning incase you have a fixed width grid set up.</p>
<p>The size of the grid may be influenced by the <a target="_blank" href="https://www.w3.org/TR/css-grid-1/#propdef-grid-row-gap">grid-row-gap</a>, <a target="_blank" href="https://www.w3.org/TR/css-grid-1/#propdef-grid-column-gap">grid-column-gap</a> and <a target="_blank" href="https://www.w3.org/TR/css3-align/#propdef-justify-content">justify-content</a>, <a target="_blank" href="https://www.w3.org/TR/css3-align/#propdef-align-content">align-content</a> . Which sadly, can add additional space between tracks too.</p>
<p>So, be careful while computing fixed widths within the grid.</p>
<h3 id="heading-bonus-we-can-all-contribute-to-making-the-docs-better">BONUS: We can all contribute to making the DOCS better</h3>
<p>Because I’m a kind soul, I’ve added one more tip here ?</p>
<p>The Spec was written by humans. And it so happens that humans can make mistakes.</p>
<p>While reading the spec, I spotted a tiny typo.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/OhansEmmanuel/status/885370706938277889?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E885370706938277889&amp;ref_url=https%3A%2F%2Fmedium.com%2Fmedia%2Fac1d37edf183b9e848a0aaf5c656a070%3FpostId%3Dfb3983aa5e0"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>At the time, I wasn’t particularly sure what to do. So, I asked around on Twitter.</p>
<p>The kind <a target="_blank" href="https://www.freecodecamp.org/news/11-things-i-learned-reading-the-css-grid-specification-fb3983aa5e0/undefined">Jen Simmons</a> helped file an issue on github, and it got fixed.</p>
<p>So, what’s the moral?</p>
<p>You can help make the docs better by contributing in whatever way possible.</p>
<p>Yes, you!</p>
<p>Let’s make the web better, together.</p>
<h3 id="heading-want-to-become-pro">Want to become Pro?</h3>
<p>Download my free CSS Grid guide, and also get two quality interactive Flexbox courses for free!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*u2ew8JU87UuAmSYWY1y8Vg.png" alt="Image" width="800" height="533" loading="lazy">
<em>How to Master the CSS Grid, and what to build along the way (Free PDF Guide)</em></p>
<p><a target="_blank" href="http://eepurl.com/dcNiP1">Get them now</a> ?</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
