<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mateusz Kirmuć</title>
    <description>The latest articles on DEV Community by Mateusz Kirmuć (@mateuszkirmuc).</description>
    <link>https://dev.to/mateuszkirmuc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F833660%2Fc410ec78-bad0-42d3-b83d-33c246ed425d.png</url>
      <title>DEV Community: Mateusz Kirmuć</title>
      <link>https://dev.to/mateuszkirmuc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mateuszkirmuc"/>
    <language>en</language>
    <item>
      <title>CSS Grid: repeat function — beyond basics</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Wed, 03 Aug 2022 13:50:58 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-repeat-function-beyond-basics-32ce</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-repeat-function-beyond-basics-32ce</guid>
      <description>&lt;p&gt;Hello. In today's article, I want to tell you more about the CSS Grid repeat() function. Beyond its &lt;a href="https://dev.to/mateuszkirmuc/css-grid-sizing-functions-4d4j"&gt;basic abilities&lt;/a&gt;, this inconspicuous function offers some extremely powerful feature: allows you to &lt;strong&gt;dynamically change a number of tracks relative to available space&lt;/strong&gt;. Here, I’ll show you how it works.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;p&gt;So far I told you that the repeat() function can be used as a shortcut for long, repetitive tracks size definition. You can achieve this functionality by providing an integer as the first argument of a function call. This is convenient because helps avoid long lines of code making code cleaner and more readable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: repeat(5, 200px);

instead of:

grid-template-columns: 200px 200px 200px 200px 200px;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Besides integer, the repeat() function accepts two additional keywords as its first argument. These keywords are &lt;strong&gt;auto-fit&lt;/strong&gt; and &lt;strong&gt;auto-fill&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    grid-template-rows: repeat(auto-fit, 1fr);
    grid-template-columns: repeat(auto-fill, 200px);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Keyword as the first argument of repeat() function.
&lt;/h2&gt;

&lt;p&gt;Using keywords as a function argument causes the number of tracks in a given dimension to be dynamically adjusted to available space within the grid container. This behavior is common for both keywords.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
   ...
   grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/fBjOk2XpMWO7M4FXEu/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/fBjOk2XpMWO7M4FXEu/giphy.gif" width="480" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how new tracks are added when enough free space becomes available, and how existing tracks are removed when available space shrinks.&lt;/p&gt;

&lt;p&gt;Also, keep in mind that using this method &lt;strong&gt;every existing or newly created track is explicit&lt;/strong&gt;. This means, for example, you can refer to the tracks relative to the last line (using negative line numbers).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="item"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

.container {
    ...
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}

.item {
    ...
    grid-column: -1 / -2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/2czxzDSVyGl72rmXNu/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/2czxzDSVyGl72rmXNu/giphy.gif" width="480" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The differences between auto-fill and auto-fit keywords.
&lt;/h2&gt;

&lt;p&gt;The main difference between both keywords lays in collapsing of tracks. The collapsed track is the track that takes no space in a given dimension. The usage of the auto-fill keyword does not allow the tracks to collapse, even if they do not contain a grid item inside them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="item"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="item"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="item"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

.container {
    ...
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yrh6RJ_F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/094bborh95t6fmmp9z0d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yrh6RJ_F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/094bborh95t6fmmp9z0d.png" alt="Image description" width="583" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how all the tracks have a non-zero width. This behavior doesn’t change, no matter how many tracks contain grid items.&lt;/p&gt;

&lt;p&gt;Usage of the auto-fit keyword force tracks without any grid item to collapse. Occupied tracks take the maximum possible size allowed by their definition. This is possible because their size is not restricted by the size of not occupied tracks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="item"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="item"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="item"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

.container {
    ...
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jrGPcZo6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h41aj45ndgq0ex73atu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jrGPcZo6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h41aj45ndgq0ex73atu.png" alt="Image description" width="583" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep in mind that even though collapsed columns are not visible, they exist as a part of the grid (here on the right side of the grid).&lt;/p&gt;

&lt;h2&gt;
  
  
  Restrictions on the type of the second argument.
&lt;/h2&gt;

&lt;p&gt;The use of the repeat() function with the auto-fill/auto-fit keyword restricts the type of the second argument. The allowed type must belong to the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#fixed-size"&gt;fixed-size&lt;/a&gt; group of allowed types. According to mdn &lt;code&gt;&amp;lt;fixed-size&amp;gt;&lt;/code&gt; can take the form of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage"&gt;length-percentage&lt;/a&gt; value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/minmax"&gt;minmax()&lt;/a&gt; function with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;min given as a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage"&gt;length-percentage&lt;/a&gt; value&lt;/li&gt;
&lt;li&gt;max given as one of a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage"&gt;length-percentage&lt;/a&gt; value, a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex_value"&gt;flex&lt;/a&gt; value, or one of the following keywords: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#min-content"&gt;min-content&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#max-content"&gt;max-content&lt;/a&gt;, or &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#auto"&gt;auto&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/minmax"&gt;minmax()&lt;/a&gt; function with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;min given as a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage"&gt;length-percentage&lt;/a&gt; value or one of the following keywords: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#min-content"&gt;min-content&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#max-content"&gt;max-content&lt;/a&gt;, or &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#auto"&gt;auto&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;max given as a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length-percentage"&gt;length-percentage&lt;/a&gt; value&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Multiple use of the repeat function in a grid definition.
&lt;/h2&gt;

&lt;p&gt;It’s possible to define a structure of a grid in a given dimension using multiple repeat() function calls. However, when the first call uses the auto-fill/auto-fit keyword as a first argument, any subsequent call must use the following pattern: &lt;code&gt;repeat(&amp;lt;integer&amp;gt;, &amp;lt;fixed-size&amp;gt;)&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Valid: */
repeat(auto-fit, 100px), repeat(3, 20%)
repeat(auto-fill, 10%, repeat(10, minmax(100px, 500px))

/* Invalid: */
repeat(auto-fit, minmax(100px, 1fr)) repeat(auto-fill, 70%)
repeat(auto-fill, minmax(min-content, 100px)) repeat(auto-fit, 1fr);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CSS Grid: custom grid item placement — grid template</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 27 Jun 2022 11:24:32 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-custom-grid-item-placement-grid-template-glh</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-custom-grid-item-placement-grid-template-glh</guid>
      <description>&lt;p&gt;Hello. Today's article will be the last one dedicated to custom grid item placement inside the grid. Previously, I focused mainly on describing how to change default grid item positioning using grid-row(column)-start(end) CSS properties (and their shorthands). Now, I want to show you a different approach based on the concept of a grid template.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Naming grid item using the grid-area property.
&lt;/h2&gt;

&lt;p&gt;The discussed method requires that every grid item that needs to be custom positioned should contain its own name. You can name grid item using the same grid-area CSS property which I described &lt;a href="https://dev.to/mateuszkirmuc/css-grid-custom-grid-item-placement-basics-ech"&gt;in my previous article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Aside from the arguments I already mentioned, this property takes a single argument of type &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident"&gt;custom-ident&lt;/a&gt; which acts as a name for this grid item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-item {
  grid-area: myCustomName;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Positioning of named grid items using the grid-template-areas property.
&lt;/h2&gt;

&lt;p&gt;After naming each element, you can use those names to define the &lt;strong&gt;grid template&lt;/strong&gt;. This can be done with the grid-template-areas CSS property which is the property of the grid container element.&lt;/p&gt;

&lt;p&gt;Keep in mind that all examples presented in this article will share the following common definitions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: repeat(5, 1fr);
  grid-template-columns: repeat(5, 1fr);
}

.grid-item {
  grid-area: item;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A grid template is some kind of representation of a container grid. Its size however does not have to correspond to the size of the container grid — may be larger or smaller. Using previously defined names, you can plan the placement of each grid inside the template which will correspond to placement in a real grid.&lt;/p&gt;

&lt;p&gt;The grid-template-areas property takes any number of &lt;strong&gt;non-empty string arguments&lt;/strong&gt;. Every argument represents a single row of the grid, starting from the top. Cells in rows are separated using space and may be one of two values: name or dot. The name refers to the named grid item and the dot represents an empty cell, not occupied by any grid item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-areas: 
    ". . . . ."
    ". . item . ."
    ". . . . ."
    ". . . . ."
    ". . . . .";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2AJQt1B1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48iuwl3rndompmglhr71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2AJQt1B1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48iuwl3rndompmglhr71.png" alt="Image description" width="700" height="398"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-areas: 
    ". . . . ."
    ". . item . ."
    ". . . . .";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5xM4YL_x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zq8kkwvpfkho7j6n1zws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5xM4YL_x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zq8kkwvpfkho7j6n1zws.png" alt="Image description" width="700" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second example shows that a number of string arguments in grid-template-areas property (3) do not have to match the number of rows defined in the grid (5).&lt;/p&gt;

&lt;p&gt;Each row can contain any number of cells, but this number must be equal in all rows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  /* invalid: number of cells in rows are different */
  grid-template-areas: 
    ". ."
    ". . item . ."
    ". . . . . . . . . . .";
}

.container {
  grid-template-areas: 
    ". . ."
    ". item ."
    ". . .";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iWOSBm9W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4hegddrqacdw2uzafnv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iWOSBm9W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4hegddrqacdw2uzafnv.png" alt="Image description" width="700" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that number of cells in each row does not have to match the number of columns defined in the grid.&lt;/p&gt;

&lt;p&gt;If adjacent names in the grid template (both between columns and rows) are the same, the grid item will be assigned to the appropriate grid area.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-areas: 
    ". . . . ."
    ". item item . ."    
    ". item item . ."
    ". . . . ."    
    ". . . . .";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9pfa04oD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wslodamcd2vqtczmij64.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9pfa04oD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wslodamcd2vqtczmij64.png" alt="Image description" width="700" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A group of adjacent names must form a rectangular shape, otherwise, such a layout will be invalid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  /* invalid: adjacent names not form rectangular shape */
  grid-template-areas: 
    "item . . . ."
    "item item . . ."    
    "item item item . ."
    ". . . . ."    
    ". . . . .";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assigning a grid item to a selected grid area (or grid cell) will cause that lines that define the boundaries of this area will automatically receive appropriate names. These names are formed according to the following formula: &lt;code&gt;item name + prefix&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-areas:
    ". . . . ."    
    ". . . . ."
    "item item . . ."
    "item item . . ."
    ". . . . .";
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c7FZbEhb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvo1t050it4zu83ki5px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c7FZbEhb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvo1t050it4zu83ki5px.png" alt="Image description" width="700" height="401"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>css</category>
    </item>
    <item>
      <title>CSS Grid: custom grid item placement — beyond basics</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 20 Jun 2022 14:16:46 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-custom-grid-item-placement-beyond-basics-22d</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-custom-grid-item-placement-beyond-basics-22d</guid>
      <description>&lt;p&gt;Hello. In my previous article, I talked about basic methods of custom grid item placement inside the grid. Today, I want to extend this subject by explaining all cases of using grid item custom placement CSS properties with a string argument.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;p&gt;So far I covered some basic argument combinations used with grid item custom placement CSS properties (grid-row/column-start/end and their shorthands). Today I want to focus on every possible combination containing string argument.&lt;/p&gt;

&lt;p&gt;Every example presented today will be simplified to a single grid item and single dimension as the same rules are applicable for multiple items and the second dimension.&lt;/p&gt;

&lt;h2&gt;
  
  
  String as a single argument.
&lt;/h2&gt;

&lt;p&gt;If you remember, the string argument refers to the grid line name if such exist. If we use string as a single argument, these line names should contain additional prefix: -start in case of grid-row/column-start and -end in case of grid-row/column-end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [line] 1fr [line line-start] 1fr [line] 1fr [line line-end] 1fr [line];
}

.item {
  grid-column-start: line;
  grid-column-end: line;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kp3cz1al685nx6us46e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kp3cz1al685nx6us46e.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how lines without prefixes are ignored during determining the size of the expected grid area occupied by grid item.&lt;/p&gt;

&lt;p&gt;In case when no line with the required prefix exists, the first line with a name identical to the string will be used (counting from left or top grid edge). &lt;strong&gt;However, this applies only to -start prefix and grid-row/column-start properties.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1] 1fr [col2] 1fr [col3 line] 1fr [col4] 1fr [col5 line];
}

.item {
  grid-column-start: line;
  grid-column-end: line;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7mjj0qnsomvsow44vqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7mjj0qnsomvsow44vqg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how the grid-column-end property falls to default (col4) as no -end prefixed line name was founded.&lt;/p&gt;

&lt;h2&gt;
  
  
  String argument with a number.
&lt;/h2&gt;

&lt;p&gt;Another combination we can use is a string argument with a number. This combination refers to the n-th line with a name identical to the string (counting from the left or top grid edge), where n is equal to the number argument.&lt;/p&gt;

&lt;p&gt;Notice that argument order is irrelevant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1 line] 1fr [col2 line] 1fr [col3 line] 1fr [col4 line] 1fr [col5 line];
}

.item {
  grid-column-start: 2 line;
  grid-column-end: line 5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnzwdmyhbye3e2elosu16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnzwdmyhbye3e2elosu16.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Negative number arguments are allowed. In such case lines with the given name will be searched from right to left (or bottom to top) edge of the grid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1 line] 1fr [col2 line] 1fr [col3 line] 1fr [col4 line] 1fr [col5 line];
}

.item {
  grid-column-start: -2 line;
  grid-column-end: line -4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frzwtylf6ne27b8cnxrfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frzwtylf6ne27b8cnxrfi.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the number argument is larger than the number of lines in a given dimension, then it is assumed that all implicit lines (if exist) contain such a name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1 line] 1fr [col2 line] 1fr [col3 line] 1fr [col4 line] 1fr [col5 line];
  grid-auto-columns: 20px;
}

.item {
  grid-column-start: 4 line;
  grid-column-end: 7 line;
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wfkqnf3bbqwu2spuyaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wfkqnf3bbqwu2spuyaf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that narrow columns on the right side of the grid are implicit.&lt;/p&gt;

&lt;h2&gt;
  
  
  String argument with span keyword.
&lt;/h2&gt;

&lt;p&gt;We can use a string argument with a span keyword as well. This combination refers to the first line with a name identical to the string, starting from the left (or top) edge of the grid.&lt;/p&gt;

&lt;p&gt;However, to effectively use &lt;strong&gt;any combination&lt;/strong&gt; of string argument with the span, both -start and -end properties should be defined, and only one of which should contain the span keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1] 1fr [col2] 1fr [col3] 1fr [col4] 1fr [col5];
}

.item {
  grid-column-start: col2;
  grid-column-end: span col4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftx4wjyk1vqgxkpx52suk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftx4wjyk1vqgxkpx52suk.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moreover, &lt;strong&gt;in any case&lt;/strong&gt; of using the span keyword with string, the line number that -end property refers to should not be larger than the line number that -start property refers to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1] 1fr [col2] 1fr [col3] 1fr [col4] 1fr [col5];
}

.item {
  /* invalid: -start property refers to line 5, -end property refers to line 1 */
  grid-column-start: col5;
  grid-column-end: span col1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A combination of arguments can be even more complex. We can use the previous span + string combination with a number. This is similar to using a string argument with a number, except the number cannot be negative!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1] 1fr [col2] 1fr [line col3] 1fr [line col4] 1fr [line col5];
}

.item {
  grid-column-start: col2;
  grid-column-end: span line 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxce9nz2qn6kcwwrwjntx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxce9nz2qn6kcwwrwjntx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Analogously, if the number argument is larger than the number of lines in a given dimension, then it is assumed that all implicit lines (if exist) will contain that name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  grid-template-rows: [row1] 1fr [row2] 1fr [row3] 1fr [row4] 1fr [row5];
  grid-template-columns: [col1] 1fr [col2] 1fr [line col3] 1fr [line col4] 1fr [line col5];
  grid-auto-columns: 20px;
}

.item {
  grid-column-start: col2;
  grid-column-end: span line 5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpunsuundvcw7c880r74u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpunsuundvcw7c880r74u.png" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwovao2myccggp2830esp.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Grid: custom grid item placement — basics</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Tue, 14 Jun 2022 13:12:22 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-custom-grid-item-placement-basics-ech</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-custom-grid-item-placement-basics-ech</guid>
      <description>&lt;p&gt;Hello. In today's article, I want to tell you about a custom placement of a grid item inside the grid. Most often, default grid item placement managed by auto-placement algorithm does not fulfill our layout expectations. Luckily, we can do something about it, and I’ll show you how.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;p&gt;In my previous article, I mentioned that every grid item is by default assigned to a single, unique grid cell in a specific order. The truth is, we can overwrite this behavior and assign item to whatever grid cell or grid area inside the grid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu978f7t3pucd6ormk3jl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu978f7t3pucd6ormk3jl.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how I changed the default placement of this item from top-left cell to bottom-right cell.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Grid custom placement properties.
&lt;/h2&gt;

&lt;p&gt;In order to achieve our desired custom placement, we can use four main CSS properties.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;grid-row-start&lt;/li&gt;
&lt;li&gt;grid-row-end&lt;/li&gt;
&lt;li&gt;grid-column-start&lt;/li&gt;
&lt;li&gt;grid-column-end&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those four properties represent grid lines within the grid. These are the boundaries of the selected area to which the selected item will be assigned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item {
  grid-row-start: 3;
  grid-row-end: 4;
  grid-column-start: 3;
  grid-column-end: 4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0mxqxbkwnaj7zj9olel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0mxqxbkwnaj7zj9olel.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Defining all properties is not required. We can only define one or all four. Missing lines will be determined automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.item {
  grid-row-start: 2;
  grid-column-start: 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2v2vi37xvxx9tf2h9kjf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2v2vi37xvxx9tf2h9kjf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each of the listed properties can take the same values. These are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;global CSS keywords (inherit, initial, revert, revert-layer, unset)&lt;/li&gt;
&lt;li&gt;CSS Grid-specific values: keyword ‘auto’ or some combination of number, string, and keyword ‘span’&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Global CSS keywords are shared between many different properties in CSS thus I won't cover them in this article. Here I want to focus on CSS Grid-specific values only.&lt;/p&gt;

&lt;p&gt;Keyword ‘auto’ means that the grid line will be determined automatically by auto-placement algorithm.&lt;/p&gt;

&lt;p&gt;The number simply indicates the line number in a given direction. The number can be negative, but cannot be equal to zero.&lt;/p&gt;

&lt;p&gt;String argument refers to the grid line name if such exist.&lt;/p&gt;

&lt;p&gt;The keyword ‘span’ means that we are dealing with a distance. In most cases, span is followed by a number or word. Span keyword without following part is not allowed.&lt;/p&gt;

&lt;p&gt;Let’s look at some examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  ...
  grid-template-rows: [row-one] 1fr [row-two] 1fr [row-three] 1fr [row-four];
  grid-template-columns: [col-one] 1fr [col-two] 1fr [col-three] 1fr [col-four];
}

.item {
  grid-row-start: 1;
  grid-row-end: row-three;
  grid-column-start: auto;
  grid-column-end: col-three;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmd5si7p33n5qma3r7e5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmd5si7p33n5qma3r7e5.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  ...
  grid-template-rows: [row-one] 1fr [row-two] 1fr [row-three] 1fr [row-four];
  grid-template-columns: [col-one] 1fr [col-two] 1fr [col-three] 1fr [col-four];
}

.item {
  grid-row-start: 1;
  grid-row-end: span row-four;
  grid-column-start: 1;
  grid-column-end: span 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixo4u6sq9cfs796y3kq4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fixo4u6sq9cfs796y3kq4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are more acceptable combinations of the mentioned values. For example, you can find combinations like string + number or span + string + number. I want to tell more about them in my future ‘beyond basics’ article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shorthand properties.
&lt;/h2&gt;

&lt;p&gt;If more than one grid line needs to be specified, we can use some special shorthand properties: grid-row, grid-column, or grid-area.&lt;/p&gt;

&lt;p&gt;Shorthand properties accept the same values as discussed above separated using slash or slashes.&lt;/p&gt;

&lt;p&gt;Grid-row and grid-column properties allow us to define both the start and end grid lines in a given direction. The missing definition will be replaced by auto.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  ...
  grid-template-rows: [row-one] 1fr [row-two] 1fr [row-three] 1fr [row-four];
  grid-template-columns: [col-one] 1fr [col-two] 1fr [col-three] 1fr [col-four];
}

.item {
  grid-row: 1 / row-three;
  grid-column: col-two / span 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5ehwlxx15lvs4pqjboc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5ehwlxx15lvs4pqjboc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Grid-area property enables us to define all four grid line boundaries at the same time. These definitions are separated by slashes, starting from the top line and going counterclockwise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  ...
  grid-template-rows: [row-one] 1fr [row-two] 1fr [row-three] 1fr [row-four];
  grid-template-columns: [col-one] 1fr [col-two] 1fr [col-three] 1fr [col-four];
}

.item {
  grid-area: 2 / 1 / span 2 / col-three;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5pwgdcgx3vk70x9vd4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5pwgdcgx3vk70x9vd4o.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember that grid-area property does not force us to define all four grid lines at once. In my future article, I will show what will happens if the one (or more) definition is missing and what other placement-related feature this property has to offer.&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwovao2myccggp2830esp.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Grid: nested grid</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 06 Jun 2022 10:00:29 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-nested-grid-1bdf</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-nested-grid-1bdf</guid>
      <description>&lt;p&gt;Hello. In today's article, I want to talk about nested grids. I will show you how to create grids inside the grid which can be very helpful in creating complex layouts. Let’s get started.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Nested grid.
&lt;/h2&gt;

&lt;p&gt;In my previous article, I talked about grid items. It’s important to remember that any content inside a grid item is by default positioned according to normal flow. You can change that, and one of the methods is to define a given grid item as a nested grid container.&lt;/p&gt;

&lt;p&gt;The way to create a nested grid is similar to creating a regular grid. To define a new nested grid you have to use the same display: grid property and grid track properties inside the grid item CSS rule.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;div class="grid-item nested-grid"&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

.container {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(3, 1fr);
}

.grid-item.nested-grid {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  grid-template-columns: repeat(4, 1fr);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhz210om3mbb1fqvgvoe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhz210om3mbb1fqvgvoe.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember that no element of the nested grid is inherited from the parent grid. This includes grid lines (both names and ids) and gaps between grid tracks. You have to define those on your own.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: grid;
  grid-template-columns: [first-col] 1fr [second-col] 1fr [third-col];
  grid-template-rows: [first-row] 1fr [second-row] 1fr [third-row];
  gap: 15px 2rem;
}

.grid-item.nested-grid {
  display: grid;
  grid-template-columns: [col-1] 1fr [col-2] 1fr [col-3] 1fr [col-4];
  grid-template-rows: [row-1] 1fr [row-2] 1fr [row-3] 1fr [row-4];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnr59obflwfxjevb8nvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnr59obflwfxjevb8nvk.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The nested grid can influence the size of the parent grid track that contains it. This happens when the parent grid track is flexible enough to allow it — its size should be defined using auto, fr, min-content, max-content, or fit-content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-columns: auto 1fr 1fr;
}

.grid-item.nested-grid {
  display: grid;
  grid-template-columns: 1.5em 200px;
  grid-template-rows: 150px 4rem;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44ialxrg5fo1mqty7co7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44ialxrg5fo1mqty7co7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, a nested grid container allows the creation of implicit grid tracks. Implicit grid tracks are tracks created automatically by the auto-placement algorithm. This happens when the required definition of grid tracks is missing — for example, when there are more elements to be placed than cells in the grid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;div class="grid-item nested-grid"&amp;gt;
    &amp;lt;div&amp;gt;1&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;2&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;3&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

.container {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(3, 1fr);
}

.grid-item.nested-grid {
  display: grid;
  grid-template-rows: 1fr;
  grid-template-columns: 1fr 1fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqs6j8t1272857qpkuaz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqs6j8t1272857qpkuaz.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that the nested grid should have only one row, according to its definition. The auto-placement algorithm creates an additional, implicit row to create the required place for a third grid item.&lt;/p&gt;

&lt;p&gt;I will discuss more about implicit tracks and auto-placement algorithm in one of my feature articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Subgrid value.
&lt;/h2&gt;

&lt;p&gt;As a bonus, I want to tell you about some very promising feature improving the creation of layouts using a nested grid. This feature included in Level 2 of the CSS Grid Layout specification is implemented currently only in Firefox 71 (and up). That’s why here I want to make a preview of all changes that come along with it.&lt;/p&gt;

&lt;p&gt;The mentioned feature is an additional ‘subgrid’ value that may be used with grid-template-rows/grid-template-columns properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-item.nested-grid {
  grid-template-rows: subgrid;
  grid-template-columns: subgrid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using subgrid value, the nested grid will inherit grid tracks definition as well as grid-line names, and track gaps from the parent grid in a given dimension. Grid-lines numbers however won’t be inherited.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: [col-1] 1fr [col-2] 1fr [col-3] 1fr [col-4];
}

.grid-item.nested-grid {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: subgrid; 
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseewqgy0uiu8dasw61kc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseewqgy0uiu8dasw61kc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how the nested grid ‘inherits’ vertical tracks from the parent grid, as well as the gaps between them and line names.&lt;/p&gt;

&lt;p&gt;Grid gaps can be overwritten inside the definition of the nested grid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(3, 1fr); 
  column-gap: 20px;
}

.grid-item.nested-grid {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: subgrid; 
  column-gap: 50px; 
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6z9g0d5sbe37qgn10vwx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6z9g0d5sbe37qgn10vwx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also specify your own grid line names by putting them in square brackets after the subgrid value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: [col-1] 1fr [col-2] 1fr [col-3] 1fr [col-4];
}

.grid-item.nested-grid {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: subgrid [sub-col-1] [sub-col-2] [sub-col-3]; 
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzkl9atr4aoja6d2u1bb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzkl9atr4aoja6d2u1bb3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep in mind that instead of regular nested grid behavior, the subgrid will prevent the creation of implicit grid tracks in a given dimension.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;div class="grid-item nested-grid"&amp;gt;
    &amp;lt;div&amp;gt;1&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;2&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;3&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

.container {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(3, 1fr);
}

.grid-item.nested-grid {
  display: grid;
  grid-template-rows: subgrid;
  grid-template-columns: 1fr; 
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsg0h5vb7cbn7xwyflh5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgsg0h5vb7cbn7xwyflh5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, an additional track for the third element won’t be created, which results in the overlapping of two elements. &lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwovao2myccggp2830esp.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CSS Grid: grid-items</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 30 May 2022 11:50:38 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-grid-items-2ej4</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-grid-items-2ej4</guid>
      <description>&lt;p&gt;Hello. Today I want to talk about one of the main building blocks of CSS Grid: grid-item elements. Knowing what grid-item elements are and what role they play is necessary to build the most basic layouts using CSS Grid. I hope you will find this content useful. Let’s begin.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Grid-item definition.
&lt;/h2&gt;

&lt;p&gt;Grid-item is an HTML element that is &lt;strong&gt;directly nested&lt;/strong&gt; inside grid-container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;div&amp;gt; &amp;lt;!-- grid-item --&amp;gt;
    &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt; &amp;lt;!-- not grid-item --&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The grid-item element must be able to contain content (other HTML elements or text). However, some of empty-elements (like &lt;code&gt;&amp;lt;img/&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;) also may be treated as grid-item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- All elements inside this container are grid-items --&amp;gt;
&amp;lt;div class="container"&amp;gt;
  &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
  &amp;lt;img src="..." /&amp;gt;
  &amp;lt;input value="..."/&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What’s important, even another grid can play the role of a grid-item element. These are called nested grids and I will talk about them in one of the future articles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5W8oiH4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8xzf0b9mg17wblrcwp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5W8oiH4G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8xzf0b9mg17wblrcwp3.png" alt="Image description" width="635" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The default placement of grid-item elements inside the grid.
&lt;/h2&gt;

&lt;p&gt;The grid-item elements must be placed in some organized way inside the grid. Responsible for this is a so-called auto-placement algorithm. Each grid-item is assigned to a separate part of the grid. By default, this grid part is a unique single grid-cell.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BcuRqbLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bimaufa0w15aqi45365v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BcuRqbLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bimaufa0w15aqi45365v.png" alt="Image description" width="635" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Grid-item elements are assigned to cells in a specific order. By default, all cells in the first row from left to right are assigned first. Then the cells from the second row are assigned and so on until all grid-items have been assigned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NQJiwcLt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gcbgddgnrxk6fgnzdv2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NQJiwcLt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gcbgddgnrxk6fgnzdv2.png" alt="Image description" width="635" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Default grid-item alignment inside grid-cell.
&lt;/h2&gt;

&lt;p&gt;By default, the size of the grid-item element is equal to the size of its assigned cell. Grid-item element fills the available space inside the cell.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--McZiE7TN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7a3h2anbpe3ca51qo862.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--McZiE7TN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7a3h2anbpe3ca51qo862.png" alt="Image description" width="635" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom grid-item placement or alignment.
&lt;/h2&gt;

&lt;p&gt;As mentioned, the previously described grid-item placement/alignment methods are the default methods used by the auto-placement algorithm. However, these methods can be overridden by the developer. Here are the examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The developer can assign more than one grid-item to the same grid-cell.&lt;/li&gt;
&lt;li&gt;The developer can change the order of assigning grid-items to cells.&lt;/li&gt;
&lt;li&gt;The developer can assign a grid-item to a part of the grid larger than a single cell.&lt;/li&gt;
&lt;li&gt;The developer can increase or decrease the size of grid-item.&lt;/li&gt;
&lt;li&gt;The developer can change the alignment of grid-item inside the cell.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8j_Be0gA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhrwpiukeh25a2bzh2rm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8j_Be0gA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhrwpiukeh25a2bzh2rm.png" alt="Image description" width="635" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The subject of custom grid-item placement or alignment is a bit more extensive, so I will describe it in more detail in separate articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Edge cases.
&lt;/h2&gt;

&lt;p&gt;It should be mentioned that there are some specific cases related to the topic of grid-item that I have not covered in this article. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What happens if you use text or not mentioned empty-elements as grid-item?&lt;/li&gt;
&lt;li&gt;What happens if there are more grid-items than cells?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions, while important, are beyond the scope of a simple introduction to grid-items. Therefore, I will try to answer them soon when I will discuss more advanced issues related to this subject.&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CSS Grid: repeat function — basics</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Wed, 25 May 2022 13:38:03 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-repeat-function-basics-ijc</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-repeat-function-basics-ijc</guid>
      <description>&lt;p&gt;Hello. Today I want to talk about the last function specific to CSS Grid: repeat function. This simple, yet powerful tool can make your life much easier when building complicated layouts. Let’s dive in!&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Function definition.
&lt;/h2&gt;

&lt;p&gt;The function can be used only as a value of grid-template-columns or grid-template-rows CSS properties. It can be used several times in single property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: repeat(...) repeat(...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function takes two arguments: positive number or one of two special keywords (auto-fill or auto-fit). The type of the first argument determines the available values for the second argument and the final result. Therefore this article will be dedicated only to the numeric argument. The use of auto-fill and auto-fit keywords is a little more complex subject and deserves a separate article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-rows: repeat(10, ...) repeat(5, ...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value of the second argument takes exactly the same syntax as the value of grid-template-columns/grid-template-rows CSS properties. This means we can use a combination of any method used to define track size (like length type, percentage, fr unit, sizing keywords, or sizing function) along with grid lines names. You can check out one of my previous &lt;a href="https://dev.to/mateuszkirmuc/css-grid-defining-the-grid-58j9"&gt;articles&lt;/a&gt; as a reminder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-rows: repeat(3, 1fr 10px 20% auto fit-content(10px));

grid-template-columns: repeat(2, [first] 1px [second, abcd] 1fr);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Resulted value is pretty straightforward: it is the second argument multiplied by the first argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: repeat(3, 1fr 50px);

is equivalent to:

grid-template-columns: 1fr 50px 1fr 50px 1fr 50px;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZOT90yBd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mlxlan3ntzz8aweg0d3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZOT90yBd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mlxlan3ntzz8aweg0d3l.png" alt="Image description" width="587" height="475"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grid-template-columns: repeat(2, [a] 100px [b] 50px [c]);

is equivalent to:

grid-template-columns: [a] 100px [b] 50px [a, c] 100px [b] 50px [c];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JXsT8QZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yy9rvcer9jrwseawlose.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JXsT8QZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yy9rvcer9jrwseawlose.png" alt="Image description" width="587" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how grid line names are applied to according grid line.&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CSS Grid: sizing functions</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 23 May 2022 11:34:27 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-sizing-functions-4d4j</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-sizing-functions-4d4j</guid>
      <description>&lt;p&gt;Hello. Today I want to talk about CSS Grid sizing functions. This is an alternative way to define grid track size. Together with lengths, fr unit, and sizing keywords, the sizing function creates a comprehensive set of tools dedicated to creating the most challenging layouts. Let’s dive in.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fit-content function.
&lt;/h2&gt;

&lt;p&gt;Fit-content is a function that takes one argument of type length or percentage and returns the calculated size of the grid track. Returned size can be equal to either min-content, max-content, passed argument, or available space.&lt;/p&gt;

&lt;p&gt;Keep in mind that all of the examples contained in this article has the following CSS definition of grid container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    width: 400px;
    height: 400px;
    grid-template-rows: 1fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the argument of the fit-content function is smaller than the min-content size, then the size of the grid track will be equal to the min-content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fit-content(argument) = min-content

when: 

argument &amp;lt; min-content
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HfgHpO54--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6t0fx3e8adh89vsm7t6m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HfgHpO54--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6t0fx3e8adh89vsm7t6m.png" alt="Image description" width="459" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the argument is larger than the size of max-content and max-content size is smaller than the available space, the size of the grid track will be equal to max-content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fit-content(argument) = max-content 

when: 

argument &amp;gt; max-content

and 

max-content &amp;lt; available space 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GFkanjQC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/plc6ggqheurj0887gjsv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GFkanjQC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/plc6ggqheurj0887gjsv.png" alt="Image description" width="459" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the argument is smaller than available space and smaller than max-content, then the size of the grid track will be equal to the argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fit-content(argument) = argument

when: 

argument &amp;lt; available space

and

max-content &amp;gt; argument 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L1M-KIfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5eddqic9ydzay3emqn7d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L1M-KIfi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5eddqic9ydzay3emqn7d.png" alt="Image description" width="459" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, when both the argument and max-content are larger than the available space, then the size of the grid track will be equal to the available space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fit-content(argument) = available space

when:

argument &amp;gt; available space

and

max-content &amp;gt; available space 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zDaOvdlh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7u2c2o5o93338r0c4lxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zDaOvdlh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7u2c2o5o93338r0c4lxh.png" alt="Image description" width="459" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Minmax function.
&lt;/h2&gt;

&lt;p&gt;Minmax is an additional function used for describing grid track size. This function returns the range of sizes that grid track can take depending on the layout. Minmax function accepts two arguments. Grid track size cannot be smaller than the first argument, and larger than the second argument.&lt;/p&gt;

&lt;p&gt;The first argument can be one of the following types: length, percentage, or sizing keyword (min-content, max-content, auto). This argument defines the minimum size that a track can take in any possible layout. What’s important, the calculated size of the track can be smaller than the min-content.&lt;/p&gt;

&lt;p&gt;The same data types apply to the second argument with an additional flex type (fr unit). This argument defines the maximum size that a track can take in any possible layout. Track size can be as large as the calculated size of the second argument when this size is smaller than the available space. Otherwise, the maximum size of the track will be equal to the available space.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s----fMLUUS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4hh06dwjh0fv6adka2h5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s----fMLUUS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4hh06dwjh0fv6adka2h5.gif" alt="Image description" width="428" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the second argument size is smaller than the available space, the maximum track size is equal to the argument.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WcO4iT_Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6txqon6jtlo6ie5so8e.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WcO4iT_Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6txqon6jtlo6ie5so8e.gif" alt="Image description" width="428" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that track size can shrink only to the width described by the first argument (50px). The minimum size here is still less than min-content.&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Grid: sizing keywords</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 16 May 2022 15:38:04 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-sizing-keywords-5734</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-sizing-keywords-5734</guid>
      <description>&lt;p&gt;Hello. Today I want to talk about some special CSS Grid keywords which are useful to define the size of grid tracks. The ability to use these keywords will allow you to precisely determine your desired grid track sizes. So let’s dive in.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Introducing sizing keywords
&lt;/h2&gt;

&lt;p&gt;When comes to CSS Grid there are only three keywords you can use to determine the size of tracks. These keywords are auto, min-content, and max-content. All of them are allowed to use in both grid-template-colums and grid-template-rows CSS properties.&lt;/p&gt;

&lt;h2&gt;
  
  
  Min-content and max-content
&lt;/h2&gt;

&lt;p&gt;If you want to make the size of the grid track dependent on its content, you should use one of two keywords: min-content or max-content. Min-content grid track will try to keep the minimum size without overflowing its content. The max-content track however assumes that the free space to expand is infinite and takes the ideal width for its content.&lt;/p&gt;

&lt;p&gt;Let me show you some examples showing the difference between the mentioned keywords. Keep in mind that every image contains two containers: container with one min-content grid column on the left and container with one max-content grid column on the right.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3Ta8Hu_a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wl2ynfqvae6bb9lxopd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3Ta8Hu_a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wl2ynfqvae6bb9lxopd.png" alt="Image description" width="880" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see here, there is no difference in sizes between min-content and max-content columns. The reason is that the image has its default fixed size which won't change unless you explicitly tell it to. Text content on the other hand has the ability to ‘compress’ its size depending on the situation. This compression is done using text wrapping (singe words won't break). Knowing that, let’s replace the image from the above example with some text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g1nT0eoy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nph913ft0tpjzzx43w9u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g1nT0eoy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nph913ft0tpjzzx43w9u.png" alt="Image description" width="880" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time columns' widths are different. Min-content column forces its text content to wrap while the max-content column expands so far that no text wrapping is needed. Notice that the min-content column is as width as the longest word and the max-content column is now wider than the container itself.&lt;/p&gt;

&lt;p&gt;What will happen when a column contains more than one type of content? Below is an example of the columns containing both image and text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cG0gHuGD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9hqaeh3kg68tr2593c8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cG0gHuGD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9hqaeh3kg68tr2593c8.png" alt="Image description" width="880" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In both cases, the widest element determines the size of the column. In the case of the min-content, this element is the image or longest word. In the case of the max-width column, this is an image or the entire text. Notice how both types of content are vertically separated inside the column. I want to discuss this behavior in one of my future articles. &lt;/p&gt;

&lt;h2&gt;
  
  
  Auto keyword
&lt;/h2&gt;

&lt;p&gt;Auto keyword is related to fr unit which I described in the previous two articles. It determines analogously that the grid track should fill all the available space in a given axis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    ...
    grid-template-columns: auto auto;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x4D9a9ti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdtl4nsrbwa2emkft4y2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x4D9a9ti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdtl4nsrbwa2emkft4y2.png" alt="Image description" width="880" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, there are two main differences between auto keyword and fr unit. First, the auto keyword is not a unit, so you cannot use it with a numeric value (e.g. &lt;code&gt;2auto&lt;/code&gt;) like you can with fr. Second, the auto keyword always ‘loses’ with fr unit, when both are used together. Look at the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    ...
    grid-template-columns: auto 1fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gkae00Yc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5v3h29w4i7o78eje8ass.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gkae00Yc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5v3h29w4i7o78eje8ass.png" alt="Image description" width="811" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might expect that the auto column will fill an equal amount of space to the fr column in the horizontal dimension. However, the presence of the fr column causes the auto column to shrink its size to content.&lt;/p&gt;

&lt;p&gt;Notice that in the case of text content, auto grid track behaves differently than min-content/max-content grid track. When auto is mixed with fr, the auto-track never forces text content to wrap unless the auto-track fills all the available space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    ...
    width: 200px;
    grid-template-columns: auto 1fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aU8qC4H0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42npppm744f8qic9dt5h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aU8qC4H0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42npppm744f8qic9dt5h.png" alt="Image description" width="880" height="491"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Grid: fr unit — beyond basics</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 09 May 2022 14:31:02 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-fr-unit-beyond-basics-3036</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-fr-unit-beyond-basics-3036</guid>
      <description>&lt;p&gt;Hello. In today's article, I want to extend the knowledge about fr unit contained in my previous post. Here I want to discuss some less common cases related to this subject. I hope you will find it useful.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fr unit is not allowed in CSS calc function.
&lt;/h2&gt;

&lt;p&gt;Let’s imagine we have a simple layout composed of two vertical and one horizontal grid track. Each column has an equal size of 1fr as in the example below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjtmno7swgm4pb4xp8atp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjtmno7swgm4pb4xp8atp.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we came up with the idea, that will be great to shrink one column by 20px, leaving some extra space on the right side of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs1snw9j88vsvlzfpam6l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs1snw9j88vsvlzfpam6l.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How can we accomplish this change? One of the potential approaches is the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/calc()" rel="noopener noreferrer"&gt;calc function&lt;/a&gt;. This is a great method to calculate values using simple math operations. Calc function accepts values of different data types including those representing distance. Let's add something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
    ...
    grid-template-columns: 1fr calc(1fr - 20px);
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What will happen when we try to use fr unit in the calc function? Unfortunately, the function won’t accept this expression. The reason is the fr unit is not compatible with the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/length" rel="noopener noreferrer"&gt;length data type&lt;/a&gt; (or any other data type that the calc function can accept). Even though it may seem that the fr unit represents the length (part of available space) it cannot be used in the calc function because of the not accepted data type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fr unit with indefinite size container
&lt;/h2&gt;

&lt;p&gt;In all examples presented by me so far CSS Grid algorithm has a relatively easy job with calculating flexible track size. All it needs to do was calculate the length of 1fr and then multiply this value by flex factor for every flexible track. However, there is one condition for this to work — container size must be definite. In the case of CSS Grid, this means that the container must have directly specified width or height or at least be a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements" rel="noopener noreferrer"&gt;block-level&lt;/a&gt; element (the last one concerns only for horizontal axis)*.&lt;/p&gt;

&lt;p&gt;Now, let’s consider the case when container size is indefinite. Using the following example I want to show you how the CSS Grid algorithm computes the lengths of flexible columns. Below we have a container with the fixed height, described using &lt;code&gt;display: inline-grid&lt;/code&gt; (inline-level element). This container contains a grid with one non-flexible and two flexible columns. Each of the flexible columns contains some text content inside**.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    display: inline-grid;
    grid-template-columns: 200px 2fr 1fr;
    ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following image shows what this layout would look like before the space distribution of flexible columns is started. You can notice that the 2fr column isn’t yet twice as large as the 1fr column because so far each flexible column adjusts its width to content.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4mk1bl04qakg71b6i7ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4mk1bl04qakg71b6i7ly.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The size of each text content is fixed and the algorithm will use those values to calculate a length of 1fr. First, it divides each text width with the respective flex factor. Such obtained values are compared and the highest one will be used to represent 1fr.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bt0i3k9l8kynbcsylgu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bt0i3k9l8kynbcsylgu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally calculated 1fr value will be used to define the sizes of the flexible columns. Each flexible column will take a width equal to 1fr multiplied by the respective flex factor. Notice that now the middle column is much wider increasing the total width of the container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxrbswz8hdhryuprxqwc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxrbswz8hdhryuprxqwc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Flex factors can be fractions.
&lt;/h2&gt;

&lt;p&gt;It’s important to know that we are not forced to always use integers as flex factors. Flex factors can be fractions. In this case, the process of calculating the width of flexible tracks depends on the sum of all factors. When the sum is greater than 1, this process is similar. First, the length of 1fr is calculated by dividing leftover space by the sum of flex factors. Then, each flexible track receives a size equal to the product of &lt;strong&gt;the calculated 1fr value times the respective flex factor&lt;/strong&gt;. Below is a simple example with one non-flexible and two flexible columns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    ...
    grid-template-column: 100px 1.4fr 2.2fr
    width: 400px
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzma5ush80tuefmcdnk7u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzma5ush80tuefmcdnk7u.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1fr = leftover space / sum of flex factors

1fr = (400px - 100px) / (1.4 + 2.2)

1fr = 83.33px
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when the sum of flex factors is less than 1, each flexible track receives a size equal to the product of &lt;strong&gt;leftover space times the respective flex factor&lt;/strong&gt;. There is no need to calculate the length of 1fr. Notice in the example below that the total size of all tracks is less than the size of the container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    ...
    grid-template-column: 100px 0.4fr 0.5fr
    width: 400px
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwcoizc9d0uyp7k8jrt5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuwcoizc9d0uyp7k8jrt5.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flexible column width = leftover space * flex factor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The size of a flexible track cannot be smaller than its fixed-size content.
&lt;/h2&gt;

&lt;p&gt;At the end of this article, I want to discuss the relation between the size of the flexible track and its static-size content. Defining grid track as flexible, we assume that it takes some part (or all) of leftover space. However, it’s important to know that in some cases, the flexible track may take more space than we expect. This is happen because a flexible track cannot be smaller than its fixed-size content. Let’s look at the following example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container {
    ...    
    grid-template-column: 1fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frc7orovo03zbmi6wzunf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frc7orovo03zbmi6wzunf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, a flexible column should take all the available space (equal to container width as this layout consists of only 1 column). However, the column contains fixed-size text content which is wider than the available space. Thus, the final width of a flexible column is larger than the container width. &lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc" rel="noopener noreferrer"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwovao2myccggp2830esp.png" alt="Buy Me A Coffee"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;*By default block-level element occupies the entire horizontal space of its parent element. This not concerns vertical axis. Block-level element without specified height will be indefinite in the vertical axis.&lt;/p&gt;

&lt;p&gt;**It’s important to remember that such layout requires that text content is placed inside grid-items, not in grid columns directly. I have chosen not to mention about grid-items to simplify this example.&lt;/p&gt;

</description>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Grid: fr unit — basics</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Tue, 26 Apr 2022 10:10:47 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-fr-unit-basics-21cm</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-fr-unit-basics-21cm</guid>
      <description>&lt;p&gt;Hello. Today, I want to talk about some very powerful tool available in the CSS Grid tool belt — fr unit. I was surprised there is so much to talk about, so I decided to split this article into two smaller parts. Today’s part will be dedicated to all the basics that anyone needs to know to understand how fr unit works. In the future part, I want to cover all the edge cases related to this subject.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Grid track
&lt;/h2&gt;

&lt;p&gt;In terms of fr unit definition, it’s important to know what the term grid track means. Grid track in simple words is a column or row in a grid. You may think of it as space between two adjacent grid lines (horizontal or vertical).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WD9lLKJh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlxa0xb097wx6pisn9c3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WD9lLKJh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlxa0xb097wx6pisn9c3.png" alt="Image description" width="880" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you may recall we define grid using two CSS properties: grid-template-columns/grid-template-rows. This way we specify the size of every track in a grid. Grid track may be flexible when described using fr unit, and non-flexible, when described using any other unit (like px, rem, % etc).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
  ...
  grid-template-columns: 300px 1fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CEoJXKAh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf4aetzuxus3aukc104o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CEoJXKAh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf4aetzuxus3aukc104o.png" alt="Image description" width="807" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fr unit
&lt;/h2&gt;

&lt;p&gt;Fr unit is a special unit available only in CSS Grid, supported in most popular browsers. It is used to determine the size of the grid track and means that the track can take some (or all) of the available free space. Free space is an area not occupied up by any non-flexible grid tracks or gaps. Look at the above example where the right column stretch to all available space left by a non-flexible left column.&lt;/p&gt;

&lt;p&gt;Of course, we can use more than one flexible grid track in our grid. Their sizes are calculated by the CSS Grid algorithm. If there are not any non-flexible grid tracks, space is distributed between flexible tracks with specified proportions. To calculate the proportions algorithm use flex factors — the numerical value of the unit (e.g flex factor in ‘3fr’ is 3). Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
    ...
    grid-template-rows: 1fr 2fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BlVRIxKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1df245mh0o8up09t5715.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BlVRIxKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1df245mh0o8up09t5715.png" alt="Image description" width="793" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you may notice the height of the container is split between two horizontal grid tracks in 1:2 proportion. This means that the lower row takes twice as much space as the upper row (1/3 vs 2/3 of container height). The simple formula shows what part of available space given track will take:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;free space fraction = flex factor / sum of all flex factors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if the grid contains more than one non-flexible grid track along with multiple flexible grid tracks? First, the algorithm calculates available space. It sums up all non-flexible tracks sizes, then subtracts this value from the total size of the container. Finally, available space is split between flexible tracks according to declared proportion. Let’s looks at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
    ...
    grid-template-columns: 100px 5rem 1fr 2fr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yCfmaAv5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07mxk7q2hzbwpon8ci3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yCfmaAv5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07mxk7q2hzbwpon8ci3n.png" alt="Image description" width="793" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the end, let’s consider some gaps between grid tracks. Available space is additionally reduced by the sum of all gaps. You can see the difference in flexible grid track sizes in the below example. Notice how flexible columns decrease it’s size whereas the size of non-flexible grid tracks stays unchanged.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
    ...
    grid-template-columns: 100px 5rem 1fr 2fr;
    column-gap: 30px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RnOgebzH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddxop1ln01l5pvvii8dq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RnOgebzH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddxop1ln01l5pvvii8dq.png" alt="Image description" width="793" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fr unit vs percent
&lt;/h2&gt;

&lt;p&gt;Some would argue that this new fancy unit is unnecessary as we can achieve the same effect using percents. Well, that's not entirely true. Let’s consider the following example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a-dythgQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6xkyr1qi2mpqicge914.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a-dythgQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6xkyr1qi2mpqicge914.png" alt="Image description" width="793" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To reproduce this example using percents we should use a special CSS calc function. Here’s how it would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
    ...
    grid-template-columns: 200px calc((100% - 200px) * 0.25) calc((100% - 200px) * 0.75);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This looks far less readable than using fr units. Moreover, we are forced to manually update flexible calc functions whenever the non-flexible width column changes. The presented example is very simple, but in real-world cases, there may be much more columns, grids, and more complicated proportions to handle. In such circumstances changing one column size, may require several adjustments to restore correct proportions.&lt;/p&gt;

&lt;p&gt;What about gaps? How to include them in our calc functions? In the case of fr unit gaps are handled automatically for us, here’s not. Let’s see how columns definition may look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid-container {
    ...
    column-gap: 10px;
    grid-template-columns: 200px calc((100% - 200px - 2 * 10px) * 0.25) calc((100% - 200px - 2 * 10px) * 0.75);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we need to manually calculate the total gap space and include it in every calc function. Not to mention how easily the proportions of the grid may fall apart if we change gap size or non-flexible column width. In more complicated layouts this may turn into a nightmare.&lt;/p&gt;

&lt;p&gt;At the end of this article, it is worth mentioning that we do not have to abandon percentage units in favor of fr. Both units get along pretty well and allow you to create desired layouts. Remember that columns defined using percentages are non-flexible:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G8kowIre--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/323rm8k8w71eecq3h0b8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G8kowIre--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/323rm8k8w71eecq3h0b8.png" alt="Image description" width="790" height="413"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;   &lt;/p&gt;

</description>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Grid: defining the grid</title>
      <dc:creator>Mateusz Kirmuć</dc:creator>
      <pubDate>Mon, 25 Apr 2022 10:29:08 +0000</pubDate>
      <link>https://dev.to/mateuszkirmuc/css-grid-defining-the-grid-58j9</link>
      <guid>https://dev.to/mateuszkirmuc/css-grid-defining-the-grid-58j9</guid>
      <description>&lt;p&gt;Hello. Today’s short post is part of a series in which I try to present to you my knowledge about the CSS Grid tool. So far, I have introduced some basic and general principles about the purpose and operation of this tool. With today’s post, I would like to show some real examples of how to carry out the first stage of creating a layout, i.e. how to define a grid.&lt;/p&gt;

&lt;p&gt;This article is part of my CSS Grid introduction series. If you want to check out my previous posts, &lt;a href="https://dev.to/mateuszkirmuc/css-grid-tutorial-table-of-contents-1g4"&gt;here&lt;/a&gt; you can find the whole table of contents.&lt;/p&gt;




&lt;h2&gt;
  
  
  Marking an item as a grid container.
&lt;/h2&gt;

&lt;p&gt;The basic operation that must be performed to enable work with the CSS Grid is to mark the selected DOM element as a grid-container. This can be done in CSS using the display property. There are two values this property accepts: grid and inline-grid. The value of the grid means that the future grid-container will be an element of the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements"&gt;block type&lt;/a&gt;. Similarly, the value of inline-grid means an element of type &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements"&gt;inline&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x3zK4uId--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqo9657wl0mq47kqxqqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x3zK4uId--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqo9657wl0mq47kqxqqf.png" alt="Image description" width="880" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Determining the size of the grid.
&lt;/h2&gt;

&lt;p&gt;After marking the selected DOM element as a grid-container, we can proceed to the definition of the grid. The obligatory action here is to determine its size. In my previous post, you can read that a grid is a collection of vertical and horizontal grid-lines that form rows and columns. We define the size of the grid by specifying the width of each column (row) using the grid-template-columns/grid-template-rows properties. In their basic variant, they accept length values corresponding to the widths of respective columns or rows, starting from the left column and the top row.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PH8-RuS6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fqi4uwz9ij7b0jc689pc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PH8-RuS6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fqi4uwz9ij7b0jc689pc.png" alt="Image description" width="880" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TpbQE_LL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0wmixcuj19s61uolpf3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TpbQE_LL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0wmixcuj19s61uolpf3.png" alt="Grid composed of 5 columns and 3 rows" width="880" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The width of the columns and rows can be determined by using all known length values that are available in the CSS language (such as px, em,%, etc.). We also have at our disposal special length units, keywords, and functions. These are methods that are only available in CSS Grid, and you can find out more about them in my future posts.&lt;/p&gt;

&lt;p&gt;The size of the defined grid may be less than or equal to the size of the containing grid-container. In some circumstances, it is possible to define a grid larger than a container, however, the grid overflows only in the horizontal dimension.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--000ohdtW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7rwrqqfpsrw3gsvhwlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--000ohdtW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7rwrqqfpsrw3gsvhwlm.png" alt="The size of the grid can be smaller, equal, or larger than the size of the container" width="880" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The dimensions of the grid can be fixed or variable. If the width or height is variable, it may depend on the sizes of the container or viewport. We can also limit the variability (or immutability) of the grid dimensions only to a certain range. This is possible thanks to the previously mentioned features available only in CSS Grid.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tutx9RY9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zicy89phd5pklv1w7uz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tutx9RY9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zicy89phd5pklv1w7uz.gif" alt="Variability of the grid width within specific ranges of the container width" width="275" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Giving your own names to grid-lines.
&lt;/h2&gt;

&lt;p&gt;Each grid-line element has a minimum of two default names that are used to identify it. Each default name is unique to a given line. Line names are especially important when defining the grid-areas — necessary elements for the layout creation process. Default names are assigned automatically as consecutive positive numbers (counting from the left and top edge of the grid) or consecutive negative numbers (counting from the right and bottom edge of the grid).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FNIv_Rws--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/408vdghugwhle13uzghf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FNIv_Rws--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/408vdghugwhle13uzghf.png" alt="Default grid-lines names" width="880" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to the names assigned automatically, it is possible to give the lines optional custom names. We can give any number of custom names for each line. Here, the grid-template-columns/grid-template-rows properties will come in handy again. Names are placed in square brackets between the widths of individual columns or rows. They are assigned from the left edge of the grid to the right (for vertical lines) and from the top edge to the bottom (for horizontal lines). Custom names do not have to be unique, we can assign the same names to many lines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MqS9SSSQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho3uvfmytuecud6bpj3d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MqS9SSSQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho3uvfmytuecud6bpj3d.png" alt="Image description" width="880" height="138"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--99TnqrYH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vuityf53ol2tdo41o7o7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--99TnqrYH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vuityf53ol2tdo41o7o7.png" alt="Custom names of grid-lines elements" width="880" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining the space between columns/rows.
&lt;/h2&gt;

&lt;p&gt;Finally, I would like to tell you about the possibility of defining gaps between adjacent rows or columns inside the grid. Importantly, we can only define the spaces between columns (rows), not between the edge of the grid and the column (or row).&lt;/p&gt;

&lt;p&gt;Gaps are defined with the column-gap/row-gap property. They take a single value that defines the size of the gap described in units of CSS length. In this case, it is not possible to use special CSS Grid length units, keywords, or functions. If we define gaps in both directions at the same time, it is worth using the property gap, which merges the previous two properties into one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--usJLC1_b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gdb76wovurgpsv6ng4r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--usJLC1_b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gdb76wovurgpsv6ng4r.png" alt="Image description" width="880" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1s7FR3Pa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edkchh9ctn83qjogttao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1s7FR3Pa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edkchh9ctn83qjogttao.png" alt="Gaps between adjacent rows/columns" width="880" height="365"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thank you for reading this short article. If you want to read more content like this you can follow my dev.to or &lt;a href="https://twitter.com/MateuszKirmuc"&gt;twitter&lt;/a&gt; account. Also, feel free to give me any form of feedback. I'd love to read any comments from you. See you soon in my next article!&lt;/p&gt;




&lt;p&gt;PS. If you would like to support my work, I will be grateful for a cup of coffee. Thank you. ❤️ &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/mateuszkirmuc"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z6B5Q-X_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wovao2myccggp2830esp.png" alt="Buy Me A Coffee" width="201" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
