<?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>Forem: Avi Thour</title>
    <description>The latest articles on Forem by Avi Thour (@thouravi).</description>
    <link>https://forem.com/thouravi</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%2F455250%2Fd8af6663-7ad7-4c0d-ab01-fda8ef63f710.png</url>
      <title>Forem: Avi Thour</title>
      <link>https://forem.com/thouravi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/thouravi"/>
    <language>en</language>
    <item>
      <title>Learning CSS Grid For the First Time</title>
      <dc:creator>Avi Thour</dc:creator>
      <pubDate>Thu, 20 Aug 2020 08:31:32 +0000</pubDate>
      <link>https://forem.com/thouravi/learning-css-grid-for-the-first-time-5amb</link>
      <guid>https://forem.com/thouravi/learning-css-grid-for-the-first-time-5amb</guid>
      <description>&lt;p&gt;Hey Everyone, my first time writing a post and thought &lt;strong&gt;CSS Grid&lt;/strong&gt; is the best topic to share with you as this is what I am learning today.&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%2Fi%2F5t73cl3j81hkv4selflb.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%2Fi%2F5t73cl3j81hkv4selflb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am not going to explain what it is and what it does, we will simply start with coding it out. First of all, this is the HTML of our CSS 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%2Fi%2Fjs1beall09d3ycke90l3.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%2Fi%2Fjs1beall09d3ycke90l3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before starting anything with the classes, I am adding flex properties to the body to center align all the items.&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%2Fi%2F7np9xthrsubl806l91u2.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%2Fi%2F7np9xthrsubl806l91u2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start with the .container - &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;width: 960px;&lt;/code&gt; - Setting a width of 960px to the whole container&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;display: grid;&lt;/code&gt; - This is the first step of creating our CSS grid. We will set display to grid in the container class.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grid-template-columns: 1fr 1fr;&lt;/code&gt; - Now we are adding two columns to the grid. 1fr means 1 fraction which means 100% of the width, here we have 1fr x 2 which means each column gets 50% of the width of the container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grid-template-rows: 1fr 1fr 1fr 1fr;&lt;/code&gt; - Similarly, we are now adding 4 rows to the grid with 1fr.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grid-gap: 1rem;&lt;/code&gt; - Once we have defined our grid, let's add some gap to it. we can use grid-gap to add gutter space around rows and columns.&lt;/li&gt;
&lt;/ol&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%2Fi%2Fphd8s9nyigwk42sv7i5x.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%2Fi%2Fphd8s9nyigwk42sv7i5x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, we will add some CSS for each .item in the grid.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;padding: 50px;&lt;/code&gt; - Added padding of 50px to each of the item.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;border-radius: 5px;&lt;/code&gt; - Added Border Radius of 5px.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;border: 5px solid #171717;&lt;/code&gt; - Added 5px solid border around items.&lt;/li&gt;
&lt;/ol&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%2Fi%2Fqpfn445s8mo3swp5ftfy.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%2Fi%2Fqpfn445s8mo3swp5ftfy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Our CSS Grid should look like this till now.&lt;/strong&gt;&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%2Fi%2Ftssiwxwcnspjswia5h0w.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%2Fi%2Ftssiwxwcnspjswia5h0w.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, we will start make our header and footer to get all the column size.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;.header { grid-column: 1/4; }&lt;/code&gt; - We are specifying that our grid item header needs all the column space in the container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;.footer { grid-column: 1/4; }&lt;/code&gt; - We are specifying that our grid item footer needs all the column space in the container.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;It will result into this:&lt;/strong&gt;&lt;br&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%2Fi%2Fbzlnswenzl12iy8ff8cb.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%2Fi%2Fbzlnswenzl12iy8ff8cb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alright, we got out header and footer look good. Time to give space to sidebar and main box.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;.sidebar { grid-row: 2/5; grid-column: 1/2; }&lt;/code&gt; - Here we are doing two things. First, setting row to take space from 2nd row to 5th and the second is to take columns space from 1st to 2nd.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;.main {grid-row: 2/5; grid-column: 2/4; }&lt;/code&gt; - Here we are asking our grid to set our row space from row 2nd to 5th and column space from 2nd to 4th.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Adding this to the CSS, our Grid will look like this:&lt;/strong&gt;&lt;br&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%2Fi%2Fb7gx2uml8r0321linb30.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%2Fi%2Fb7gx2uml8r0321linb30.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we are left with our Box1 and Box2. We will give them 50% column space to each using &lt;strong&gt;grid-column&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;.box1 { grid-column: 1/2; }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.box2 { grid-column: 2/4; }&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;We are complete with our First CSS Grid.&lt;/strong&gt;&lt;br&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%2Fi%2Fwk8wxn7ja40c5xm012cj.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%2Fi%2Fwk8wxn7ja40c5xm012cj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make it look good, we can add some gradient background and drop shadow to the item class and tada! This looks stunning.&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%2Fi%2F5t73cl3j81hkv4selflb.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%2Fi%2F5t73cl3j81hkv4selflb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for reading out till the end, It was my first ever post on dev.to - Full Codepen: &lt;a href="https://codepen.io/avithour/pen/jOqMdmG" rel="noopener noreferrer"&gt;https://codepen.io/avithour/pen/jOqMdmG&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>design</category>
      <category>codepen</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
