<?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: Stephany</title>
    <description>The latest articles on DEV Community by Stephany (@ltephanysopez).</description>
    <link>https://dev.to/ltephanysopez</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%2F196469%2F4822725b-77ee-4eaf-919d-3d9a011457c8.jpg</url>
      <title>DEV Community: Stephany</title>
      <link>https://dev.to/ltephanysopez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ltephanysopez"/>
    <language>en</language>
    <item>
      <title>Web Layouts with CSS Grid: The Basics</title>
      <dc:creator>Stephany</dc:creator>
      <pubDate>Tue, 30 Jul 2019 21:31:03 +0000</pubDate>
      <link>https://dev.to/ltephanysopez/css-grid-the-basics-4ppp</link>
      <guid>https://dev.to/ltephanysopez/css-grid-the-basics-4ppp</guid>
      <description>&lt;h1&gt;
  
  
  What is CSS Grid?
&lt;/h1&gt;

&lt;p&gt;CSS Grid is a technique in CSS that allows developers to create responsive web design layouts more easily and consistently across browsers. With CSS Grid, we can transform our elements from this layout:&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%2Fraw.githubusercontent.com%2Fltephanysopez%2Fintro-to-web-dev%2Fmaster%2Fdocs%2Fimages%2Fnormal-html-layout.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%2Fraw.githubusercontent.com%2Fltephanysopez%2Fintro-to-web-dev%2Fmaster%2Fdocs%2Fimages%2Fnormal-html-layout.png" alt="Standard HTML Layout"&gt;&lt;/a&gt;&lt;br&gt;
to this: &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%2Fraw.githubusercontent.com%2Fltephanysopez%2Fintro-to-web-dev%2Fmaster%2Fdocs%2Fimages%2Fcss-grid-layout.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%2Fraw.githubusercontent.com%2Fltephanysopez%2Fintro-to-web-dev%2Fmaster%2Fdocs%2Fimages%2Fcss-grid-layout.png" alt="CSS Grid Layout"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What separates a good website from a bad website is the ability to structure the contents of your website in the most approachable way to your users. Your website should be clean with an easy-to-follow navigation system to contribute to a usable webpage layout.&lt;/p&gt;

&lt;p&gt;A layout that is easy to follow will give the site’s visitor easy access to the valuable and important information on your website. When content is difficult to find on a webpage, visitors get agitated and choose to leave the site with the possibility of not returning.&lt;/p&gt;


&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;Let’s begin! To create a grid, we’ll first need to create a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element with the class name grid. The &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag is used as a container that divides the HTML document into sections. We use &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; elements to group together HTML elements and apply CSS styles to many elements at once.&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="grid"&amp;gt;

&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fantastic! This &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element states that on our webpage, we have a designated section named grid. Now, it’s time for us to add items inside our grid that we’ll use to style. We’ll do this by adding smaller sections with &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; elements and give them individual IDs.&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="grid"&amp;gt;
   &amp;lt;div id="item-1"&amp;gt; 1 &amp;lt;/div&amp;gt;
   &amp;lt;div id="item-2"&amp;gt; 2 &amp;lt;/div&amp;gt;
   &amp;lt;div id="item-3"&amp;gt; 3 &amp;lt;/div&amp;gt;
   &amp;lt;div id="item-4"&amp;gt; 4 &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, we have one large container full of smaller containers that make up a grid. Let’s turn our container into a grid by modifying it in our CSS.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now, let’s see what our grid looks like:&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%2Fraw.githubusercontent.com%2Fltephanysopez%2Fintro-to-web-dev%2Fmaster%2Fdocs%2Fimages%2Fnormal-html-layout.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%2Fraw.githubusercontent.com%2Fltephanysopez%2Fintro-to-web-dev%2Fmaster%2Fdocs%2Fimages%2Fnormal-html-layout.png" alt="No change to our elements"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because we haven’t defined any rows or columns in our grid yet, the elements will remain stacked on top of each other. Let’s change this by adding two new properties to our grid class: &lt;code&gt;grid-template-columns&lt;/code&gt; and &lt;code&gt;grid-template-rows&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;.grid {
     display: grid;
     grid-template-columns: 100px 100px;
     grid-template-rows: 50px 50px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each value provided to the &lt;code&gt;grid-template-columns&lt;/code&gt; and &lt;code&gt;grid-template-rows&lt;/code&gt; properties dictate how wide we want our columns (100px) and how tall we want our rows (50px). So now, our grid will look like this: &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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fgrid-one.png%3Fraw%3Dtrue" 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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fgrid-one.png%3Fraw%3Dtrue" alt="Adding rows and columns to our grid in CSS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Excellent! Let’s create a small gap between the elements in our grid by adding the &lt;code&gt;grid-gap&lt;/code&gt; 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 {
     display: grid;
     grid-template-columns: 100px 100px;
     grid-template-rows: 50px 50px;
     grid-gap: 10px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding the &lt;code&gt;grid-gap&lt;/code&gt; property, we obtain the following result:&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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fgrid-two.png%3Fraw%3Dtrue" 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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fgrid-two.png%3Fraw%3Dtrue" alt="CSS Grid with rows, columns, and a gap between all elements"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h1&gt;
  
  
  Position and Resizing
&lt;/h1&gt;

&lt;p&gt;In addition to grid rows and columns, we also have grid lines that identify the start and end of a column. &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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2F2d-grid-layout.png%3Fraw%3Dtrue" 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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2F2d-grid-layout.png%3Fraw%3Dtrue" alt="Grid Lines"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the figure above, we can see that although we have 3 columns, we have 4 grid lines where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Column 1 starts at line 1 and ends at line 2&lt;/li&gt;
&lt;li&gt;Column 2 starts at line 2 and ends at line 3&lt;/li&gt;
&lt;li&gt;Column 3 starts at line 3 and ends at line 4&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;To create multi-dimensional layouts, all we’ll need to do is modify where each element in our grid starts and ends. Let’s modify our layout so that the first item in our grid spans across all three columns.&lt;/p&gt;

&lt;p&gt;In my HTML file, I'm going to create a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element with the class name grid that contains nine unique elements with matching ids inside:&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="grid"&amp;gt;
     &amp;lt;div id=“item-1”&amp;gt; 1 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-2”&amp;gt; 2 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-3”&amp;gt; 3 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-4”&amp;gt; 4 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-5”&amp;gt; 5 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-6”&amp;gt; 6 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-7”&amp;gt; 7 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-8”&amp;gt; 8 &amp;lt;/div&amp;gt;
     &amp;lt;div id=“item-9”&amp;gt; 9 &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we've created all our elements in the HTML file, let's style our grid class by adding 3 columns that are 300px wide and 3 rows that are 300px tall. I’ve also specified that the first element in our grid should span over 3 entire columns by specifying which lines the column should start and end on with two new properties: &lt;code&gt;grid-column-start&lt;/code&gt; and &lt;code&gt;grid-column-end&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;.grid {
   display: grid;
   grid-template-columns:300px 300px 300px;
   grid-template-rows:300px 300px 300px;
   grid-gap:15px;
}

#item-1 {
   grid-column-start:1;
   grid-column-end:4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see how the styling above affects our grid:&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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fmulti-dimensional-layout.png%3Fraw%3Dtrue" 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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fmulti-dimensional-layout.png%3Fraw%3Dtrue" alt="Multi-dimensional CSS Grid Layout"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we've styled the first element in our grid to span across all 3 columns, all the other elements in the grid have been pushed over to the next available column.&lt;/p&gt;

&lt;p&gt;Another way to specify which grid lines an element should span across is with the shorthand &lt;code&gt;grid-column&lt;/code&gt; property, which takes two values: the starting grid line and the ending grid line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#item-1 {
   grid-column: 1/4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;And that’s the basics of CSS Grid! Using the properties we’ve gone over, you now have the availability to create multi-dimensional layouts that will best suit your website. Let's look at another example with the same number of elements as the previous example, but with different CSS styling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid {
    display: grid;
    grid-gap: 10px;
    grid-template-columns: 200px 100px 100px;
    grid-template-rows: repeat(5, 100px);
}

#item-1 {
    grid-column:1/3;
}

#item-4 {
    grid-column:2/4;
}

#item-5 {
    grid-column:1/4;
}

#item-9 {
    grid-column:1/4;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The styling above produces the following 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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fmultid-layout-example.png%3Fraw%3Dtrue" 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%2Fgithub.com%2Fltephanysopez%2Fintro-to-web-dev%2Fblob%2Fmaster%2Fdocs%2Fimages%2Fmultid-layout-example.png%3Fraw%3Dtrue" alt="Multi-dimensional Layout Example with CSS Grid"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading this tutorial! If you want to learn more about CSS Grid, check out these awesome resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grid Critters: &lt;a href="https://www.gridcritters.com/" rel="noopener noreferrer"&gt;https://www.gridcritters.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;W3Schools: &lt;a href="https://www.w3schools.com/css/css_grid.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/css/css_grid.asp&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;CSS Tricks: &lt;a href="https://css-tricks.com/snippets/css/complete-guide-grid/" rel="noopener noreferrer"&gt;https://css-tricks.com/snippets/css/complete-guide-grid/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Grid by Example: &lt;a href="https://gridbyexample.com/examples/" rel="noopener noreferrer"&gt;https://gridbyexample.com/examples/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Learn CSS Grid for free: &lt;a href="https://scrimba.com/g/gR8PTE" rel="noopener noreferrer"&gt;https://scrimba.com/g/gR8PTE&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>css</category>
      <category>webdev</category>
      <category>cssgrid</category>
    </item>
  </channel>
</rss>
