<?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: Samuel Anderson</title>
    <description>The latest articles on DEV Community by Samuel Anderson (@mranderson455).</description>
    <link>https://dev.to/mranderson455</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%2F496705%2Fae9ff2af-f29d-4e3d-a29a-b67e96c2dcdd.png</url>
      <title>DEV Community: Samuel Anderson</title>
      <link>https://dev.to/mranderson455</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mranderson455"/>
    <language>en</language>
    <item>
      <title>CSS Grid Blog Post</title>
      <dc:creator>Samuel Anderson</dc:creator>
      <pubDate>Fri, 23 Oct 2020 22:11:10 +0000</pubDate>
      <link>https://dev.to/mranderson455/css-grid-blog-post-3c5e</link>
      <guid>https://dev.to/mranderson455/css-grid-blog-post-3c5e</guid>
      <description>&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%2Fcloud.netlifyusercontent.com%2Fassets%2F344dbf88-fdf9-42bb-adb4-46f01eedd629%2F334a08d2-4cad-470f-ade4-9f3283ad3ba4%2Fmrh-css-grid-fig-02-800w-opt.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%2Fcloud.netlifyusercontent.com%2Fassets%2F344dbf88-fdf9-42bb-adb4-46f01eedd629%2F334a08d2-4cad-470f-ade4-9f3283ad3ba4%2Fmrh-css-grid-fig-02-800w-opt.png" alt="CSS Grid img"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What is CSS Grid?
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;A way to organize elements in HTML.&lt;/li&gt;
&lt;li&gt;A more in-depth alternative to flex-box.&lt;/li&gt;
&lt;li&gt;A more stripped-down version of Bootstrap columns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  How do I use CSS Grid?
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Make a container div that will contain all grid elements.&lt;/li&gt;
&lt;li&gt;Add to the CSS of the container, &lt;code&gt;display: grid&lt;/code&gt; or &lt;code&gt;display: inline-grid&lt;/code&gt; (if you want an inline grid) as well as &lt;code&gt;grid-template-columns: auto auto auto&lt;/code&gt;, with the autos being the number of columns (change it to a number to specify a column width)&lt;/li&gt;
&lt;li&gt;Create the elements (ideally divs) that will go within the container div.&lt;/li&gt;
&lt;li&gt;You're now done!&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%2Fwww.w3schools.com%2Fcss%2Fgrid_gaps.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%2Fwww.w3schools.com%2Fcss%2Fgrid_gaps.png" alt="CSS Grid img"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  While this grid technically works, there are a few things you may want to add to make the grid more specified to your needs.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Adding specified sizes for all of the grid items using a &lt;code&gt;grid-item&lt;/code&gt; class as well as setting &lt;code&gt;width: px&lt;/code&gt; and &lt;code&gt;height: px&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Adding grid padding between grid items using &lt;code&gt;grid-column-gap: px&lt;/code&gt;, &lt;code&gt;grid-row-gap: px&lt;/code&gt;, and &lt;code&gt;grid-gap: px&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Changing grid column width by changing the auto's at the end of &lt;code&gt;grid-template-columns&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Using justify-content to horizontally space the elements as you may please, such as &lt;code&gt;justify-content: space-evenly&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Using align-content to vertically space the elements as you may please, such as &lt;code&gt;align-content: center&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Making grid non-uniform
&lt;/h1&gt;

&lt;p&gt;Many times, you won't want the automatically space and sized grids that css-grid can produce, instead you may want a grid that doesn't follow the rules of &lt;code&gt;display: grid&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make each element that is non-uniform have a unique class/id, such as &lt;code&gt;item1&lt;/code&gt;, &lt;code&gt;item2&lt;/code&gt;, &lt;code&gt;item3&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;From this point you can define:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Num. of columns for elements to span using &lt;code&gt;grid-column: 1 / 3&lt;/code&gt; (goes from col. 1 to col. 3) or &lt;code&gt;grid-column: 1 / span 3&lt;/code&gt; (spans from col. 1 for 3 col.'s).&lt;/li&gt;
&lt;li&gt;Num. of rows for elements to span using &lt;code&gt;grid-row: 1 / 3&lt;/code&gt; (goes from row 1 to row 3) or &lt;code&gt;grid-row: 1 / span 3&lt;/code&gt; (spans from row 1 for 3 rows).&lt;/li&gt;
&lt;li&gt;For the &lt;em&gt;most&lt;/em&gt; precision, define the entire area using &lt;code&gt;grid-area: 1 / 3 / 3 / 4&lt;/code&gt;, where the element goes from row 1, col. 3 to row 3, col. 4 (you can use span as well).&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Template area
&lt;/h1&gt;

&lt;p&gt;To define the space an element takes up you can use &lt;code&gt;grid-template-areas: area1 area2 area3&lt;/code&gt; in the container, and &lt;code&gt;grid-area: area2&lt;/code&gt; in the grid item.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can use periods instead of area names if they are not relevant to the area names you are using (&lt;code&gt;grid-template-areas: area1 area1 . .&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;You can use this for rows as well such as:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;grid-template-areas&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; 
    &lt;span class="s2"&gt;'header header subtitle'&lt;/span&gt;
    &lt;span class="s2"&gt;'content content content'&lt;/span&gt;
    &lt;span class="s2"&gt;'footer name company'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  CSS Grid Example
&lt;/h1&gt;

&lt;p&gt;Made in Figma&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%2Fi.imgur.com%2FGxkshGN.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%2Fi.imgur.com%2FGxkshGN.png" alt="CSS Grid img"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example after being made in HTML, CSS, and Javascript:&lt;br&gt;
(with clickable advent days)&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%2Fi.imgur.com%2FAPq98oH.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%2Fi.imgur.com%2FAPq98oH.png" alt="CSS Grid img"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Use of CSS Grid in Project
&lt;/h1&gt;

&lt;p&gt;Me and my groupmate used CSS Grid everywhere. Almost all formatting is based on CSS Grid. Even things that wouldn't normally be thought of to be CSS Grid are, in fact, CSS Grid.&lt;/p&gt;
&lt;h3&gt;
  
  
  Use in Whole Calendar
&lt;/h3&gt;

&lt;p&gt;To format the entire calendar, we used CSS Grid. This is possibly the most obvious use in the website, since all the elements are literally in the shape of a grid.&lt;/p&gt;

&lt;p&gt;The hierarchy of the elements is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"flex-master"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"grid-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-sub"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we are using flex box to center the entire thing, a grid container to contains all grid elements, sub grid-containers to contain each tile and hidden image, and grid-content to contain both the background and body text.&lt;/p&gt;

&lt;h3&gt;
  
  
  Grid Tile
&lt;/h3&gt;

&lt;p&gt;We use CSS Grid even in elements with only one child, but why is that? Well, using Grid's align-items property, we can easily vertically align text which is normally a pain in normal HTML. The reason the image and content are separate is so they can have different levels of opacity.&lt;/p&gt;

&lt;p&gt;Oh, and all these tiles (31, 1 for each day) are generated purely by JS in one for-loop. This means they all share the same properties and don't clog up the main HTML page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Javacsript
&lt;/h3&gt;

&lt;p&gt;The main use of Javascript is to generate the tiles and make it so when clicked on, they reveal an image behind them. The first is pretty standard, with createElement and appendChild used to create and append the main containers.&lt;/p&gt;

&lt;p&gt;The code for revealing the image works by having an event listener and changing the opacity values for the content and image to be toggled when clicked on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;gridSub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;hideOnClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gridSub&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, to make sure each tile has an image in a easily modifiable way, we have a list of strings that are image links so that each tile at each index has an image at the same index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;imgList&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;santa.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;elf.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;imgList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;gridImg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;imgList&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;CSS grid is one more tool in a web developer's toolbelt. Knowing the info is only half of the practice, the other half comes from actual usage in a website.&lt;br&gt;
However, unlike other tools in the toolbelt, CSS grid uses a very logical and easy to visualize way of formatting elements, which alleviates the headaches of things like &lt;code&gt;float: left&lt;/code&gt; and &lt;code&gt;position: absolute&lt;/code&gt;. It is incredibly useful for formatting the basic structure of any website and I can't wait to use it in one.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
