<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by withApples on Medium]]></title>
        <description><![CDATA[Stories by withApples on Medium]]></description>
        <link>https://medium.com/@withApples?source=rss-13ca2a516f31------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*JOq41ADIttNFqyDJLcA3fQ.jpeg</url>
            <title>Stories by withApples on Medium</title>
            <link>https://medium.com/@withApples?source=rss-13ca2a516f31------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 03:10:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@withApples/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Grid Positioning — Grid Series Part 3]]></title>
            <link>https://medium.com/@withApples/grid-positioning-grid-series-part-3-1a5d01e8a3f?source=rss-13ca2a516f31------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a5d01e8a3f</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css-grid]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[grid-layout]]></category>
            <category><![CDATA[grid]]></category>
            <dc:creator><![CDATA[withApples]]></dc:creator>
            <pubDate>Wed, 20 May 2020 00:43:02 GMT</pubDate>
            <atom:updated>2020-05-20T00:43:02.789Z</atom:updated>
            <content:encoded><![CDATA[<h3>Grid Positioning — Grid Series Part 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BVzwy_dvDVoRXhYL" /><figcaption>Photo by <a href="https://unsplash.com/@bradencollum?utm_source=medium&amp;utm_medium=referral">Braden Collum</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my previous story, I talked about grid alignment and how we can arrange the grid-items and the grid itself.</p><p>This time, I will be talking about how we can position the grid-items inside the grid.</p><p>Before we get started there are a few concepts that we must understand in order to continue.</p><p><strong>Grid-Lines</strong>: Are the horizontal or vertical lines that intersect to make up the grid.</p><p><strong>Grid-Area</strong>: Consists of one or more adjacent grid-cells, where we can place one or more grid-items.</p><p>For simplicity’s sake, we will only be placing one grid-item per grid-area</p><p>Here is our starting template</p><pre>&lt;div class=”wrapper”&gt;<br>  &lt;div class=”grid-item-1&quot;&gt;One&lt;/div&gt;<br>  &lt;div class=”grid-item-2&quot;&gt;Two&lt;/div&gt;<br>  &lt;div class=”grid-item-3&quot;&gt;Three&lt;/div&gt;<br>  &lt;div class=”grid-item-4&quot;&gt;Four&lt;/div&gt;<br>  &lt;div class=”grid-item-5&quot;&gt;Five&lt;/div&gt;<br>&lt;/div&gt;</pre><p>That was the HTML, and now the CSS</p><pre>html {<br> box-sizing: border-box;<br>}</pre><pre>*, *::after, *::before {<br>  box-sizing: inherit;<br>}</pre><pre>* {<br>  margin: 0;<br>  padding: 0;<br>}</pre><pre>.wrapper {<br>  display: grid;<br>  background-color: khaki;<br>  width: 1000px;<br>  height: 400px;<br>  border: 2px solid darkkhaki;<br>  grid-template-columns: repeat(4, 200px);<br>  grid-template-rows: repeat(4, 80px);<br>}</pre><pre>.wrapper div{<br>  background-color: orange;<br>  border: 1px solid darkorange;<br>  padding: 15px;<br>  font-size: 24px;<br>  text-align: center;<br>}</pre><p>Here is the end result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X8oDsgRl97MWpNyZPH3zPw.png" /></figure><p>As we can see from the picture a grid-container of 1000x400px was created.</p><p>The grid has 4 columns of 200px each and 4 rows of 80px each.</p><p>We can see that the grid-area for each grid-item is a grid-cell, which is the default.</p><p>We can also see the grid-lines and their corresponding numbers.</p><p>Let’s go ahead and see how we can place different items within the grid.</p><p>This is what we want to accomplish</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_4-XBY_IxITjsXseN59-g.png" /></figure><p>We want for the third grid-item to:</p><ul><li>Column: start on the 2nd grid-line and end on the 4th grid line.</li><li>Row: start on the 2nd grid-line and end on the 4th grid line.</li></ul><p>So this is how we can accomplish it.</p><pre>.grid-item-3 {<br>  grid-column-start: 2;<br>  grid-column-end: 4;<br>  grid-row-start: 2;<br>  grid-row-end: 4;<br>}</pre><p>We have to detail in which grid-line we want it to start and where we wish for it to end.</p><p>Depending on if we are working on columns or rows.</p><p>If you don’t like this syntax which I personally don’t, we can use the shorthand version.</p><pre>.grid-item-3 {<br>  grid-column: 2 / 4;<br>  grid-row: 2 / 4;<br>}</pre><p>We specify what grid-lines we want to start(2) and end(4) separated by a “/”.</p><p>The end result will be exactly the same.</p><p>Let’s try it with another grid-item.</p><pre>.grid-item-5 {<br>  grid-column: 1 / 5;<br>  grid-row: 4 / 5;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7h4-KD_BuVjuOPNWtI3mww.png" /></figure><p>This caused the fifth grid-item to:</p><ul><li>Column: start on the 1st grid-line and end on the 5th grid-line, which happens to be the last one.</li><li>Row: start on the 4th grid-line and end on the 5th grid-line.</li></ul><p>Next, we want for the first grid-item to:</p><ul><li>Column: start on the 1st grid-line and end on the last grid-line(5).</li><li>Row: start on the 1st grid-line and end on the 2nd grid-line.</li></ul><p>The next piece of code does this exact thing.</p><pre>.grid-item-1 {<br> grid-column: 1 / -1;<br> grid-row: 1 / 2;<br>}</pre><p>As we can see in the grid-column definition we didn’t specify the 5th grid-line.</p><p>But instead, we used a -1, this basically means that we are stretching the item all the way to the last grid-line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qot-4axRbh4B7UxsYte8tA.png" /></figure><p>We can see it here in the end result.</p><p>Another way we can specify the position of an element is by telling it how many grid-lines we would like for that item to stretch.</p><p>In order to do this, we can use the span keyword, as the following example.</p><pre>.grid-item-2 {<br>  grid-column: 1 / span 1;<br>  grid-row: 2 / span 2;<br>}</pre><p>We can see the result below!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lqkWS5WVzYmVTY9ewZ8Byg.png" /></figure><p>We specified the 2nd grid-item to:</p><ul><li>Column: Start on the 1st grid-line and stretch(span) one grid-line.</li><li>Row: Start on the 2nd grid and stretch(span) 2 grid-lines.</li></ul><p>I would like to mention that there is also an implicit span.</p><p>When you don’t specify how many grid-lines it spans, it stretches by default 1 grid-cell.</p><pre>.grid-item-4 {<br>  grid-row: 2 / span 2;<br>  grid-column-start: 4;<br>}</pre><p>As we can see, we only specified where the column started.</p><p>I personally don&#39;t recommend this because it doesn’t seem clear where the item ends.</p><p>And we can see the result below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-FXhGKuY9oqMYN55gMNaw.png" /></figure><p>There are certain scenarios, where it will be much easier to specify how space will be distributed by naming the areas.</p><p>We do this by giving a specific grid-cell a particular name.</p><p>This will group one or more grid-cells under a certain named area.</p><p>Which can later be used to allocate a certain item in that named area.</p><pre>.wrapper {<br>   grid-template-areas: <br>     “header header header header”<br>     “side1 main main side2”<br>     “side1 main main side2”<br>     “footer footer footer footer”;<br>}</pre><pre>.grid-item-1 {<br>  grid-area: header;<br>}</pre><pre>.grid-item-2 {<br>  grid-area: side1;<br>}</pre><pre>.grid-item-3 {<br>  grid-area: main;<br>}</pre><pre>.grid-item-4 {<br>  grid-area: side2;<br>}</pre><pre>.grid-item-5 {<br>  grid-area: footer;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HdTqSlNN_-3vvGYpM6SrpA.png" /></figure><p>As we can see we first defined the areas with grid-template-areas.</p><p>Then we located each grid-item inside a specific area with grid-area.</p><p>Now, we’ll go ahead and add some gaps to the grid.</p><pre>.wrapper {<br>  grid-gap: 15px;<br>}</pre><p>This creates a gap between each column and row of 15px, as we can see in the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8fbrONPmH6EaL8rBgsOkzA.png" /></figure><p>Be aware that those items that stretch more than one grid-cell also “absorb” the gap as well.</p><p>Next, let’s go ahead and center the content both vertically and horizontally in its grid-container.</p><pre>.wrapper {<br> grid-gap: 15px;<br> justify-content: center;<br> align-content: center;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ol85ZI-a4y0KbZCjohfLgg.png" /></figure><p>As we can see it’s just as easy as adding those two properties, which we talk about in part 2(alignment)</p><p>Last but not least, we’ll go ahead and change all the HTML we added before and replace it with this.</p><pre>&lt;div class=”wrapper&quot;&gt;<br>  &lt;div class=”grid-item-1&quot;&gt;Header&lt;/div&gt;<br>  &lt;div class=”grid-item-2&quot;&gt;Side Content&lt;/div&gt;<br>  &lt;div class=”grid-item-3&quot;&gt;Main Content&lt;/div&gt;<br>  &lt;div class=”grid-item-4&quot;&gt;Side Content&lt;/div&gt;<br>  &lt;div class=”grid-item-5&quot;&gt;Footer&lt;/div&gt;<br>&lt;/div&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d49J7wl5uj3fvAlh8Brsmg.png" /></figure><p>As we can see, we made the layout of a simple page with just a few lines of code.</p><p>I hope you enjoyed my explanation.</p><p>See you around!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a5d01e8a3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grid Alignment — Grid Series Part 2]]></title>
            <link>https://medium.com/@withApples/grid-alignment-grid-series-part-2-25d871ef121b?source=rss-13ca2a516f31------2</link>
            <guid isPermaLink="false">https://medium.com/p/25d871ef121b</guid>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[grid-layout]]></category>
            <category><![CDATA[grid]]></category>
            <category><![CDATA[css-grid]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[withApples]]></dc:creator>
            <pubDate>Sun, 17 May 2020 14:41:31 GMT</pubDate>
            <atom:updated>2020-05-17T14:41:31.590Z</atom:updated>
            <content:encoded><![CDATA[<h3>Grid Alignment — Grid Series Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UvKkaPL5S2Aidmwq" /><figcaption>Photo by <a href="https://unsplash.com/@johnwestrock?utm_source=medium&amp;utm_medium=referral">Dave</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my previous post, I explained the basics of how to create columns, rows, and gaps.</p><p>This time, I will be explaining the different ways we can align the content within its grid-cell(s) and grid-container.</p><p>Let’s start with the base case and start working from there!</p><p>Here is my base HTML</p><pre>&lt;div class=”wrapper”&gt;<br>  &lt;div class=”grid-item-1&quot;&gt;One&lt;/div&gt;<br>  &lt;div class=”grid-item-2&quot;&gt;Two&lt;/div&gt;<br>  &lt;div class=”grid-item-3&quot;&gt;Three&lt;/div&gt;<br>  &lt;div class=”grid-item-4&quot;&gt;Four&lt;/div&gt;<br>  &lt;div class=”grid-item-5&quot;&gt;Five&lt;/div&gt;<br>&lt;/div&gt;</pre><p>And then my CSS</p><pre>html {<br> box-sizing: border-box;<br>}</pre><pre>*,<br>*::after,<br>*::before {<br> box-sizing: inherit;<br>}</pre><pre>* {<br> margin: 0;<br> padding: 0;<br>}</pre><pre>.wrapper {<br>  display: grid;<br>  width: 1000px;<br>  height: 400px;<br>  background-color: khaki;<br>  border: 2px solid darkkhaki;<br>  grid-template-columns: 200px 200px 200px;<br>  grid-template-rows: 100px 100px;<br>}</pre><pre>.wrapper div{<br>  background-color: orange;<br>  border: 1px solid darkorange;<br>  padding: 15px;<br>  font-size: 24px;<br>}</pre><p>This creates a grid-container of 1000x400px with a grid that has 3 columns of 200px and 2 rows of 100px.</p><p>Then, the 5 boxes are distributed evenly between the grid-cells as we can see in the picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7genrF6f9cP61bCGnNRbA.png" /></figure><p>The first thing that we will see is how we can change the alignment of the grid-items inside their grid cell(s).</p><p>If we will like to center all grid-items vertically within its grid cell(s), we can use the align-items property.</p><pre>.wrapper {<br> align-items: center;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8o-9xQ7eg5ARkyHRaTYBRw.png" /></figure><p>Let’s take into account that if we don’t set a height property in the grid-item.</p><p>It will use its intrinsic size (padding + content + border).</p><p>We can also set the align property in each grid-item individually by using the align-self property.</p><p>So, let’s give it a whirl!</p><pre>.wrapper .grid-item-1 {<br>  align-self: start;<br>}</pre><pre>.wrapper .grid-item-2 {<br>  align-self: center;<br>}</pre><pre>.wrapper .grid-item-3 {<br>  align-self: end;<br>}</pre><pre>.wrapper .grid-item-4 {<br>  align-self: stretch;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlFy6MHRofdhQCXRwTsnFQ.png" /></figure><p>As we can see, in the first row each item is aligned vertically from top to bottom depending on the start, center, and end values.</p><p>In the second row, we can see that the fourth item stretched all the space vertically of the grid-cell.</p><p>As for the fifth element, It&#39;s centered because of the align-items: center property we set before.</p><p>Now let’s remove the code we set for the align-items and align-self properties and add this new code.</p><pre>.wrapper-3 {<br>  justify-items: center;<br>}</pre><p>When we start using the justify-items property, we start working with the horizontal axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GcX-iZ0VcunspWddv9U_hA.png" /></figure><p>As I mentioned before, It uses the intrinsic width to calculate de width of the grid-item.</p><p>Then, it centers the grid-item within its grid cell(s) horizontally.</p><p>You can probably imagine that we also have a self property for justify.</p><p>And you are absolutely right!</p><p>Go ahead and the rest of the code for this example.</p><pre>.wrapper-4 .grid-item-1 {<br>  justify-self: start;<br>}</pre><pre>.wrapper-4 .grid-item-2 {<br>  justify-self: center;<br>}</pre><pre>.wrapper-4 .grid-item-3 {<br>  justify-self: end;<br>}</pre><pre>.wrapper-4 .grid-item-4 {<br>  justify-self: stretch;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Y9B-oQSDGcjgeD1qbEFeA.png" /></figure><p>As we can see, in the first row each item is aligned horizontally from left to right depending on the start, center, and end values.</p><p>On the second row, the fourth item stretches the whole width of its grid-cell.</p><p>And then, the fifth item had no property set but is affected by the align-items property that we defined before.</p><p>Now, let’s go ahead and combine the align and justify items property to see what happens.</p><p>So please go ahead and remove all the code we used for the justify-items and justify-self property and add this code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NrxxX4eDW1SwrVmnTLtoLQ.png" /></figure><p>I think the picture is self-explanatory, for the first row.</p><p>As for the second row be aware that we didn’t set any properties for the fifth grid-item but as we can see, stretch is the default value.</p><p>Once again remove all the code that we just added for the justify and align properties.</p><p>So far we have aligned the grid-items inside its grid cell(s).</p><p>Now let’s go ahead and see how we can align the content(the grid itself) with respect to its grid-container.</p><p>So please go ahead and this code.</p><pre>.wrapper {<br>  justify-content: center;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyy0G9V1KTQYYVDz1m0xxw.png" /></figure><p>As we can see, the content(grid) is now centered horizontally.</p><p>We can also use other properties like space-around to arrange the content.</p><pre>.wrapper {<br>  justify-content: space-around;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AytlyAL-hBluNE6b00PRWA.png" /></figure><p>This divides the space left between the columns and their borders.</p><blockquote><strong>Note</strong>: the default value for justify-content is start</blockquote><p>For the next scenario, go ahead and erase the code that we added for the justify-content property.</p><p>And add this code so we can center the content vertically.</p><pre>.wrapper-9 {<br>  align-content: center;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_FDDus0j_uUnFoNiejUMdw.png" /></figure><p>Next, let’s go ahead and add this other piece of code to test another value.</p><pre>.wrapper-9 {<br>  align-content: space-between;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRY48rys9fZrZtcWHi_lbQ.png" /></figure><p>The image shows that the remaining space was only divided between the columns.</p><blockquote><strong>Note</strong>: the default value for align-content is start</blockquote><p>For my last example, I will center the content in both the horizontal and vertical axis.</p><p>Go ahead and add this last piece of code.</p><pre>wrapper {<br>  justify-content: center;<br>  align-content: center;<br>}</pre><p>Here is the end result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A9woVm3o4f-1tOKT1iI0Yg.png" /></figure><p>As we can see, it was pretty easy to align the content in the center of the container.</p><p>I hope you enjoyed this article as much as I enjoyed writing it!</p><p>Please leave some claps if you like this story.</p><p>See ya!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25d871ef121b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grid Basics — Grid Series]]></title>
            <link>https://medium.com/@withApples/grid-basics-grid-series-70c8d587261b?source=rss-13ca2a516f31------2</link>
            <guid isPermaLink="false">https://medium.com/p/70c8d587261b</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[grid]]></category>
            <category><![CDATA[grid-layout]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[css-grid]]></category>
            <dc:creator><![CDATA[withApples]]></dc:creator>
            <pubDate>Fri, 15 May 2020 22:22:13 GMT</pubDate>
            <atom:updated>2020-05-17T15:21:03.828Z</atom:updated>
            <content:encoded><![CDATA[<h3>Grid Basics — Grid Series Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z73JX0KcCC0RpI6_" /><figcaption>Photo by <a href="https://unsplash.com/@chatelp?utm_source=medium&amp;utm_medium=referral">Pierre Châtel-Innocenti</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>CSS Grid is a two dimension-based system that is used to layout pages for user interfaces.</p><p>Before we start coding and seeing some examples of how it works.</p><p>First, we have to understand a couple of concepts that we’ll be using through this series.</p><p><strong>Grid</strong>: Is an intersecting set of horizontal and vertical lines that divides the space into cells. Thus creating a table-like format with columns and rows.</p><p><strong>Grid-Container</strong>: This is the space where the grid will be allocated. All of its content is then layout in a grid. Meaning that the content of this container is the grid itself.</p><p><strong>Grid-Cell</strong>: is the intersection between a row and a column in the grid. This is the smallest unit that is used in the grid.</p><p><strong>Grid-Items</strong>: Each item(direct child) of the grid-container will become a box that will be organized into one or more grid-cells.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*DKRuN3k_QR2-mfiLx77exA.png" /></figure><p>This image explains how the grid is set up without any content.</p><p>Once we create items inside the grid-container they will be allocated into each of the grid-cells that we can see in the image.</p><p>Now that we have the basic concepts out of the way, let’s get started with the examples.</p><p>Here is the HTML</p><pre>&lt;div class=”wrapper”&gt;<br>  &lt;div&gt;One&lt;/div&gt;<br>  &lt;a&gt;Two&lt;/a&gt;<br>  &lt;a&gt;Three&lt;/a&gt;<br>  &lt;div&gt;Four&lt;/div&gt;<br>  &lt;div&gt;Five&lt;/div&gt;<br>&lt;/div&gt;</pre><p>And the CSS</p><pre>html {<br>  box-sizing: border-box;<br>}</pre><pre>*,<br>*::after,<br>*::before {<br>  box-sizing: inherit;<br>}</pre><pre>* {<br>  margin: 0;<br>  padding: 0;<br>}</pre><pre>.wrapper {<br>  background-color: khaki;<br>  border: 2px solid darkkhaki<br>}</pre><pre>.wrapper &gt; * {<br> background-color: orange;<br> border: 1px solid darkorange;<br> padding: 15px;<br> font-size: 24px;<br>}</pre><p>This code creates a container that has 5 items inside it.</p><p>3 divs that are block elements and 2 anchor tags that are inline elements.</p><p>The rest is just for styling purposes so we can tell the difference between the container and its items (direct children).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRitLLb0LiXNEeh2hIMUdg.png" /></figure><p>As we can see the anchor tags align next two each other and their height property is not taken into account because they are inline elements.</p><p>On the other hand, the div tags are taken as block elements, which means their height property is taken into account and its width is 100% of the container.</p><p>Let’s see what happens once we set the grid property in the container.</p><pre>.wrapper {<br>  display: grid;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28IYnu-XXTBlcaFchy_Dhg.png" /></figure><p>A grid has been created inside the container and all of the items (direct children) have become grid-items.</p><p>Each item becomes a box and gets placed inside each grid cell, thus taking all of its available space.</p><p>By default, a single column will be created taking 100% the width of the container and then a new row for each grid-item;</p><p>Since we have 5 grid-items, 5 rows were created.</p><p>Because we didn’t specify the height of each row that was created, it will take the height needed by each grid-item.</p><p>Now let’s create some columns and see what happens.</p><pre>.wrapper {<br>  grid-template-columns: 300px 300px 300px;<br>}</pre><p>When you add this code to your CSS, it will create 3 columns of 300px each inside the grid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrtjYDq4e70GfWOELAyQmQ.png" /></figure><p>As we saw before, the rows are created automatically to fit the content and are allocated inside each grid cell.</p><p>If we would like for the space to be divided between the grid columns.</p><p>We can use the fr unit to help us distribute the available space.</p><p>Go ahead and add this piece of code</p><pre>.wrapper {<br>  grid-template-columns: 1fr 1fr 1fr;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jotWESLGYRi9EqOqhaxffw.png" /></figure><p>There is an alternate syntax to do this without repeating each unit per column.</p><pre>.wrapper {<br>  grid-template-columns: repeat(3, 1fr);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glIUT8h1vd6o5rd_QmEnOw.png" /></figure><p>The result is basically the same.</p><blockquote><strong>Note</strong>: Be aware that we can use the repeat function with any unit we like (%, px, fr, etc).</blockquote><p>But how does it distribute the content when we combine a relative unit like fr and an absolute unit like px or %.</p><pre>.wrapper {<br>  grid-template-columns: 200px 200px 1fr;<br>}</pre><p>Here is the end result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZVg-Mtcui3YgI9mlEMcBQ.png" /></figure><p>Basically, what happens is that the content with an absolute unit is allocated first.</p><p>In this example, the first 2 columns use a total of 400px total (200px * 2).</p><p>And the rest of the space is divided between the rest of the fr units which in this case is the last column.</p><p>If by any chance we wont to change the size of the rows that are created automatically.</p><p>We can do this by using the grid-auto-row property.</p><pre>.wrapper {<br>  grid-auto-rows: 100px;<br>}</pre><p>Here is what changed!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3QGfVxPS-HaWDDtdS30lw.png" /></figure><p>Now, every time a new column is created automatically is given the size of 100px.</p><p>Next, if we would like to define a specific size for the rows as we did with the columns.</p><p>We can use the grid-template-rows property which will define the size of each of the rows we define.</p><pre>.wrapper {<br>  grid-template-rows: 70px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StBNXXwj_K87NsQdXiAJhQ.png" /></figure><p>This created a row with a height of 70px for the first row.</p><p>Since we didn’t define the size of the second row with the grid-template-rows property, the grid-auto-rows property kicks in.</p><p>Setting the height of the second row to 100px.</p><p>Last but not least, we can define the distance between each column and/or row by using the gap property.</p><p>So go ahead and this last piece of code in your CSS.</p><pre>.wrapper { <br>  column-gap: 20px;<br>  row-gap: 15px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-fm2GsYUEGGpyGIAh2gPzg.png" /></figure><p>As we can see in the picture.</p><p>We have created a space of 20px between each column and the space of 15px between each row.</p><p>Be aware that as I mentioned before, the grid system will first allocate the size of the absolute values first.</p><p>Next, it will set the space between each column and/or row.</p><p>And then, finally, it will leave the rest of the space to be taken by the rows and/or columns with an fr unit.</p><p>That’s all for today!</p><p>If you enjoyed this story, don’t forget to leave some claps!</p><p>Until the next one.</p><p>Here is the link for part 2 of this grid series.</p><p><a href="https://medium.com/@withApples/grid-alignment-grid-series-part-2-25d871ef121b">https://medium.com/@withApples/grid-alignment-grid-series-part-2-25d871ef121b</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70c8d587261b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When does Flex-wrap kick in? — Flexbox Series Part 3]]></title>
            <link>https://medium.com/@withApples/when-does-flex-wrap-kick-in-flexbox-series-part-3-303ecdbeb765?source=rss-13ca2a516f31------2</link>
            <guid isPermaLink="false">https://medium.com/p/303ecdbeb765</guid>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[flex]]></category>
            <category><![CDATA[css-flexbox]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[withApples]]></dc:creator>
            <pubDate>Sun, 03 May 2020 12:06:41 GMT</pubDate>
            <atom:updated>2020-05-04T23:32:54.381Z</atom:updated>
            <content:encoded><![CDATA[<h3>When does Flex-wrap kick in? — Flexbox Series Part 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yAt6OEnHIWzkRmwT" /><figcaption>Photo by <a href="https://unsplash.com/@milkovi?utm_source=medium&amp;utm_medium=referral">MILKOVÍ</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hi everyone :)</p><p>In my previous posts of the flexbox series, I have talked about flex-grow and flex-shrink.</p><p>But how does flex-wrap integrate with all these previously mention tools?</p><p>Let’s find out!</p><p>Here is the boilerplate for the HTML.</p><pre>&lt;div class=”container”&gt;<br> &lt;div id=”item-1&quot; class=”item”&gt;&lt;/div&gt;<br> &lt;div id=”item-2&quot; class=”item”&gt;&lt;/div&gt;<br> &lt;div id=”item-3&quot; class=”item”&gt;&lt;/div&gt;<br>&lt;/div&gt;</pre><p>And for the CSS.</p><pre>.container {<br>  background-color: lightblue;<br>  margin:  10px auto;<br>  display: flex;<br>  padding: 20px 0;<br>  width: 900px;<br>}.item {<br>  box-sizing: border-box;<br>  width: 200px;<br>  height: 150px;<br>  background-color: lightcyan;<br>  border: 2px solid darkcyan;<br>}</pre><p>It’s a flex container of 900px wide with 3 boxes of 200x150px.</p><p>The rest is just for styling purposes only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*V63kWBS5LHJNIt2pnqvwtA.png" /></figure><p>As we can see the boxes occupy exactly a total of 600px inside its container.</p><p>But what happens when we shrink its size to 500px?</p><p>So let’s change the width of the container and see what happens.</p><pre>.container {<br>   width: 500px; <br>}</pre><p>And here is the result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*b_CkKvf9S3JmaT2r-dpvpQ.png" /></figure><p>By default, we have the properties flex-shrink set to 1 and flex-wrap set to no-wrap.</p><p>Basically what this means, is that the content will try to adjust to its new size in the same line.</p><p>Now let’s see what happens when we change the flex-wrap property to wrap.</p><pre>.container {<br>  flex-wrap: wrap;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*A57GvRN4iHOuwuink8N_sw.png" /></figure><p>Since there was no space for the 3rd box, in the first row.</p><p>A second row was created in order for the content to fit in.</p><p>This same pattern will repeat itself if we shrink the size of the container even smaller.</p><pre>.container {<br>   width: 300px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*cGsidi3K0o03XTjfS6yCyA.png" /></figure><p>Another row was created for the second box, so we now have 3 rows in total.</p><p>Emm… but what happened with the flex-grow and the flex-shrink properties in this type of case.</p><blockquote>Note: The flex-grow property default is zero. So it won’t take effect until we explicitly tell it to.</blockquote><p>Let’s find out! I’ll add this piece of code and we’ll see what happens.</p><pre>.item {<br> flex-grow: 1;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*2Mh_csNxdzqYsSmpgbYyJw.png" /></figure><p>Each box occupied the space available in each row.</p><p>So, the flex-grow property will work separately in each new row and divide it’s space accordingly with its other “row-peers”</p><p>Last but not least, we’ll see what happens with the flex-shrink property.</p><p>If we continue to shrink the size of the container, the flex-shrink property will begin to work and try to fit the content.</p><pre>.container {<br>  width: 150px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/137/1*5bLBBsxb7xqLntKPjua1Rg.png" /></figure><p>As we can see, the content adjusted accordingly to its container.</p><p>The flex-shrink property will start to work once the width of the box(flex-item) won’t fit inside its container.</p><p>If you enjoyed this post, please help me with some appreciated claps!</p><p>See Ya!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=303ecdbeb765" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flex-grow & Flex-shrink calculations explained (Part 2/2)]]></title>
            <link>https://medium.com/@withApples/flex-grow-flex-shrink-calculations-explained-part-2-2-2a73d27ba5cb?source=rss-13ca2a516f31------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a73d27ba5cb</guid>
            <category><![CDATA[flex-grow]]></category>
            <category><![CDATA[flex]]></category>
            <category><![CDATA[flex-shrink]]></category>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[withApples]]></dc:creator>
            <pubDate>Tue, 28 Apr 2020 22:48:05 GMT</pubDate>
            <atom:updated>2020-05-03T12:14:15.840Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flex-grow &amp; Flex-shrink calculations explained — Flexbox Series Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MuCJv4USmKzyDV94" /><figcaption>Photo by <a href="https://unsplash.com/@osmank?utm_source=medium&amp;utm_medium=referral">Osman Köycü</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my previous story, I talked about how flex-grow adapts it’s content to the available space left by its container.</p><p>This time, I will go into the nitty-gritty of how it does such calculations with flew-grow and flex-shrink.</p><p>First, we’ll get our HTML setup.</p><pre>&lt;div class=”container&quot;&gt;<br>  &lt;div id=”item-1&quot; class=”item”&gt;&lt;/div&gt;<br>  &lt;div id=”item-2&quot; class=”item”&gt;&lt;/div&gt;<br>  &lt;div id=”item-3&quot; class=”item”&gt;&lt;/div&gt;<br>&lt;/div&gt;</pre><p>And then our CSS.</p><pre>.container {<br>  background-color: lightblue;<br>  margin:  10px auto;<br>  display: flex;<br>  padding: 20px 0;<br>  width: 900px;<br>}</pre><pre>.item {<br>  box-sizing: border-box;<br>  width: 200px;<br>  height: 150px;<br>  background-color: lightcyan;<br>  border: 2px solid darkcyan;<br>}</pre><p>This code basically creates a flex container that has a width of 900px.</p><p>And then 3 boxes inside this container of 200px wide and 150px high.</p><p>Here is an image of the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*uM427nnR8ps66pxmZhIQOw.png" /></figure><p>By default, the flex-grow property is set to 0.</p><p>This means that the total space occupied by the 3 boxes are a total of 600px (200px * 3).</p><pre>Space occupied: 200px * 3 = 600px</pre><p>The width of the container(900px) subtracted by the amount of space occupied by the 3 boxes(600px) leaves us a total of 300px of unoccupied space.</p><pre>Unoccupied space: 900px - 600px = 300px</pre><blockquote>Note: Please be aware that the next examples will be using the 300px of unoccupied space. Which we’ll be using for the calculations.</blockquote><p>Next, let’s see what happens when we start integrating the flex-grow property to each of our items.</p><pre>.item {<br>  flex-grow: 1;<br>}</pre><p>Here is our new image!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*Zrr_sepxAVeF8cTBoSLCug.png" /></figure><p>Let’s see what happened in this case.</p><p>The flex-grow property was set to 1 in all of the boxes.</p><p>Meaning that they must organize themselves in order to occupy the space left in the container.</p><p>As I mentioned in my first example the space left in the container was 300px.</p><p>So, what we must do is add the value of all the flew-grow properties in our container, which is 3 (1+ 1+ 1).</p><pre>flex-grow-total: 1+ 1 + 1 = 3</pre><p>We now have to divide the available space (300px) by the total of flex-grow (3), giving us a total of 100px.</p><pre>space ratio: 300px / 3 = 100px</pre><p>Now, let’s calculate the final width of one the boxes but since they all have flex-grow: 1, it will be the same for all 3.</p><p>We have to multiple the space ratio(100px) by the flex-grow value(1) and added to its width (200px), this gives us a total of 300px.</p><pre>final width: 100px * 1 + 200px = 300px</pre><p>Let’s move to another example to get the hand of this calculation.</p><p>Let’s add these changes to our CSS.</p><pre>#item-2 {<br> flex-grow: 2;<br>}</pre><pre>#item-3 {<br> flex-grow: 3;<br>}</pre><p>This changes the flex-grow value of the second box to 2 and the third box to 3.</p><p>Here is the end result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*VlTW_y2GdKGJXAWniYsoCQ.png" /></figure><p>We already know that the amount of unoccupied space is a total of 300px.</p><p>So we must now calculate how much of that space will be added to the width of each box.</p><p>The first step is to add the values of their flex-grow property.</p><pre>flex-grow-total: 1 + 2 + 3 = 6</pre><p>Then we calculate the space ratio</p><pre>space-ratio: 300px / 6 = 50px</pre><p>Then we calculate the final width of each box</p><pre>box-1: 50px * 1 + 200px = 250px<br>box-2: 50px * 2 + 200px = 300px<br>box-3: 50px * 3 + 200px = 350px</pre><p>Thus, making these new values the width of its corresponding box.</p><p>But what happens when the width of the container is smaller than the size of its contents.</p><p>Let’s add this code to the end of our CSS</p><pre>.container {<br>  width: 300px;<br>}</pre><pre>#item-2 {<br>  flex-shrink: 2;<br>}</pre><p>Amazing enough, our boxes adjust to the size of its container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*c1CIivgQ4Q3Qt_U4bewrzA.png" /></figure><p>The calculations are pretty similar to the ones made for the flex-grow property but with a negative value.</p><p>We know that the new width of the container is now of 300px and that the total width of the boxes was 600px.</p><p>If we subtract these 2 numbers we get a difference of -300px that will be subtracted from each box, depending on its flex-shrink value.</p><p>By default, all of the flex-items (the boxes inside the container), get a flex-shrink value of 1.</p><p>Now let’s add the total of the flex-shrink values.</p><pre>flex-shrink-total: 1 + 2 + 1 = 4</pre><p>Then, as we did with the flex-grow properties we have to calculate the ratio.</p><pre>space-ratio: -300px / 4 = -75px</pre><p>And finally, we calculate the total width of all the boxes.</p><pre>box-1: -75px * 1 + 200px = 125px<br>box-2: -75px * 2 + 200px = 50px<br>box-3: -75px * 3 + 200px = 125px</pre><p>Last but not least, for those of you wondering what happens when we set the value of flex-shrink to 0 in all of our boxes.</p><p>This is what happens…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*u7W9uxWuRHuoJ5ZVFDQhDQ.png" /></figure><p>That’s all for today!</p><p>I hope you enjoy this post.</p><p>See you around.</p><p>Here is a link to part 3 of this series!</p><p><a href="https://medium.com/@ali.rivera.echegaray/when-does-flex-wrap-kick-in-flexbox-series-part-3-303ecdbeb765">https://medium.com/@ali.rivera.echegaray/when-does-flex-wrap-kick-in-flexbox-series-part-3-303ecdbeb765</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a73d27ba5cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gulp Intro — From Sass to minify CSS.]]></title>
            <link>https://medium.com/@withApples/gulp-intro-from-sass-to-minify-css-96c628846c1d?source=rss-13ca2a516f31------2</link>
            <guid isPermaLink="false">https://medium.com/p/96c628846c1d</guid>
            <category><![CDATA[gulpjs]]></category>
            <category><![CDATA[gulp]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[sass]]></category>
            <dc:creator><![CDATA[withApples]]></dc:creator>
            <pubDate>Tue, 28 Apr 2020 00:17:00 GMT</pubDate>
            <atom:updated>2020-04-28T00:17:00.105Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gulp Intro — From Sass to minify CSS.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eILh1VxzXs84V33A" /><figcaption>Photo by <a href="https://unsplash.com/@pankajpatel?utm_source=medium&amp;utm_medium=referral">Pankaj Patel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello there! This is my second post so far and I’m really excited… so, let’s get started.</p><p>I won’t go into explaining what gulp is since you are already here.</p><p>I’m pretty sure all you want to know is how to use gulp.</p><p>First things first, we will need a couple of things to start using gulp in our project.</p><p>So please make sure you run the following command in your terminal.</p><pre>npm i gulp gulp-cssnano gulp-sass gulp-concat-css -D</pre><p>This will install:</p><ul><li>Gulp: Toolkit to automate tasks</li><li>Gulp-cssnano: plugin to minify your CSS</li><li>Gulp-sass: plugin to transform your sass files to CSS</li><li>Gulp-concat-css: plugin to concatenate multiple CSS files into one.</li></ul><p>Next, you’ll need to create a Gulpfile.js file at the root of your project.</p><p>Then, import gulp and the plugins that we installed previously so that we may use them.</p><pre>const gulp = require(‘gulp’);<br>const concatCss = require(‘gulp-concat-css’);<br>const cssNano = require(‘gulp-cssnano’)<br>const sass = require(‘gulp-sass’);</pre><p>And now let’s create our first task that will transform all our sass files into one single CSS file.</p><p>Here is the code!</p><pre>gulp.task(&#39;sass&#39;, function sassFunc(){<br>  return gulp.src(&#39;./sass/*.scss&#39;)<br>  .pipe(sass())<br>  .pipe(concatCss(&#39;styles.css&#39;))<br>  .pipe(gulp.dest(&#39;./css&#39;))<br>});</pre><p>Woah, Man! Don’t just throw stuff at me and explained it first.</p><p>I know… I know… I’m getting there.</p><p>The first thing we will see is gulp.task which is a function that receives two arguments.</p><ol><li>A string, which will be the name of the task.</li><li>A function where you will be executing the task at hand.</li></ol><p>Next, we use gulp.src which receives a string of the location where we will be extracting our sass files.</p><p>Once we have all those files ready to use, we must transform them into CSS and then store them in one single file.</p><p>That’s where the pipe function comes in, we pass it a process or plugin as an argument so that it may handle those files and hand it to its next process.</p><p>So the first time we use the pipe function, we pass it the sass() plugin so it may transform all our files to CSS files.</p><p>The second time we use the pipe function, we use the concatCss plugin.</p><p>Which will store all our new transformed CSS files into one single file, styles.css.</p><p>Finally, we use pipe one last time to store our newly created CSS file with the gulp.dest function, that receives a string of the location where we will be storing the file.</p><blockquote>Note: Once we are done executing everything, we must return it. This, lets gulp know that the task has been completed.</blockquote><p>We just converted all our files to a single CSS file, and now we need to create another task in order to minify it.</p><p>Here is the code for the minify task.</p><pre>gulp.task(&#39;minify&#39;, function minifyFunc() {<br>  return gulp.src(&#39;./css/styles.css&#39;)<br>    .pipe(cssnano())<br>    .pipe(gulp.dest(&#39;./css&#39;));<br>});</pre><p>I won’t go into explaining what each function does since I have explained it before. But I will, in turn, explain what this code does.</p><p>First, It creates a task named minify that looks for a file styles.css in the CSS folder that’s located in the root folder of the project.</p><p>Then, it minifies the file by using the cssnano plugin</p><p>And finally, it stores it once again in the CSS folder with the same name.</p><p>The last thing that we need to do is watch for any changes in our sass files so they may be converted to CSS and then minify it.</p><p>So…let’s do that!</p><pre>gulp.task(&#39;watch&#39;, function watchFunc() {<br>  gulp.watch(&#39;./sass/*.scss&#39;, gulp.series(&#39;sass&#39;, &#39;minify&#39;));<br>});</pre><p>Here we added some new functions to the mix, watch, and series. So let me explained them first.</p><p>gulp.watch is a function that receives two arguments.</p><ol><li>A string with the location of the files that must be watched.</li><li>A series of tasks that must be executed when the change occurs</li></ol><p>gulp.series is a function that receives any number of strings of previously registered tasks</p><p>These tasks will be composed into a bigger operation that will be done, one after the other.</p><p>Now that we have that out of the way, let me explain what’s going on inside this task.</p><p>It watches for any modifications in our scss files inside the sass folder.</p><p>If it detects any changes, it executions the tasks in order, first sass, then minify.</p><p>Since we are done writing everything, make sure that you save your code and add this script in your package.json</p><pre>gulp watch</pre><p>I hope you enjoyed my explanation.</p><p>See you around!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96c628846c1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brief explanation of Flex-grow]]></title>
            <link>https://medium.com/@withApples/brief-explanation-of-flex-grow-52fbddf3dc49?source=rss-13ca2a516f31------2</link>
            <guid isPermaLink="false">https://medium.com/p/52fbddf3dc49</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[flexbox]]></category>
            <category><![CDATA[flex-grow]]></category>
            <category><![CDATA[css-flexbox]]></category>
            <category><![CDATA[flex]]></category>
            <dc:creator><![CDATA[withApples]]></dc:creator>
            <pubDate>Sat, 25 Apr 2020 17:57:38 GMT</pubDate>
            <atom:updated>2020-05-03T11:04:50.334Z</atom:updated>
            <content:encoded><![CDATA[<h3>A brief explanation of Flex-grow — Flexbox Series Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V4F1B5lG98VIX67a" /><figcaption>Photo by <a href="https://unsplash.com/@new_memel_photography?utm_source=medium&amp;utm_medium=referral">Arūnas Naujokas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hi!!! This is my first time blogging anything on the internet. I currently reside in Argentina and I’m very happy here!</p><p>So… Let’s get right to the point! I will be explaining how flex-grow calculates how much space it will take with a simple example.</p><p>For simplicity’s sake, I will only be explaining it with a flex-direction of row and dividing the space equally in the items.</p><p>Here is the base code for the HTML</p><pre>&lt;div class=”container&quot;&gt;<br>  &lt;div class=”item”&gt;&lt;/div&gt;<br>  &lt;div class=”item”&gt;&lt;/div&gt;<br>  &lt;div class=”item”&gt;&lt;/div&gt;<br>&lt;/div&gt;</pre><p>And here is the base code for the CSS</p><pre>.container {<br>  background-color: lightblue;<br>  padding: 20px;<br>  display: flex;<br>}</pre><pre>.item {<br>  box-sizing: border-box;<br>  width: 200px;<br>  height: 150px;<br>  background-color: lightcyan;<br>  border: 2px solid darkcyan;<br>}</pre><p>This code basically creates a flex container with 3 boxes inside it. Each box has a width of 200px and a height of 150px. And the rest of the code is just for styling purposes only.</p><p>Here is the result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9RlAYqEMMHHnO1gOXCSbFw.png" /></figure><p>Next, let’s add a margin to each box except for the first one and see what happens inside the container.</p><pre>.item {<br>  margin-left: 10px;<br>}<br>.item:first-child{<br>  margin-left: 0;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ba6WFAOjXelJeIibdclQlg.png" /></figure><p>As we can see all the boxes except for the first one were added a gap of 10px.</p><p>Last but not least, we will add the flex-grow property to all of the boxes inside the container and see what happens.</p><pre>.item {<br>  flex-grow: 1;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oo_nS4WMVjdKTkCRzyoYwQ.png" /></figure><p>Finally, as we can see, the rest of the available space will be equally divided between all the boxes and added to its current width.</p><p>I hope this approach can help you resolve any issues you have with flex-grow and how it calculates how much space it will take.</p><p>I’ll also leave an example in codepen, in case you need to play with some code.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fagriverae%2Fembed%2Fpreview%2FOJymLby%3Fheight%3D600%26slug-hash%3DOJymLby%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fagriverae%2Fpen%2FOJymLby&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2730539.OJymLby.small.f7c2c0a6-975f-46da-8054-a11a2e1a9ff5.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e8d3da4bdafc52f24bd111cd3c40307/href">https://medium.com/media/3e8d3da4bdafc52f24bd111cd3c40307/href</a></iframe><p>In my next post, I will explain how it divides the space when the flex-grow property varies between items.</p><p>Until the next one!</p><p>Here is part 2 of the Flexbox Series.</p><p><a href="https://medium.com/@ali.rivera.echegaray/flex-grow-flex-shrink-calculations-explained-part-2-2-2a73d27ba5cb">https://medium.com/@ali.rivera.echegaray/flex-grow-flex-shrink-calculations-explained-part-2-2-2a73d27ba5cb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52fbddf3dc49" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>