<?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: Kate Efimova</title>
    <description>The latest articles on Forem by Kate Efimova (@kefimochi).</description>
    <link>https://forem.com/kefimochi</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%2F158413%2F24a290b0-b3e7-4001-afda-3d3d5632eedf.jpg</url>
      <title>Forem: Kate Efimova</title>
      <link>https://forem.com/kefimochi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kefimochi"/>
    <language>en</language>
    <item>
      <title>Reading from Go's .Env</title>
      <dc:creator>Kate Efimova</dc:creator>
      <pubDate>Fri, 07 Feb 2020 06:18:56 +0000</pubDate>
      <link>https://forem.com/kefimochi/reading-from-go-s-env-3n2i</link>
      <guid>https://forem.com/kefimochi/reading-from-go-s-env-3n2i</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nPKCudV7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/bzr47frhmg7w17i22gw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nPKCudV7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/bzr47frhmg7w17i22gw9.png" alt="A black text divider" height="50%" width="50%"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Preface
&lt;/h1&gt;

&lt;p&gt;When you are just starting out with Go, it might be a bit overwhelming to grasp how the language works right away. As I was following this &lt;a href="https://tutorialedge.net/golang/writing-a-twitter-bot-golang/"&gt;tutorial&lt;/a&gt;, to my surprise it logged all .env variables as undefined. It was not easy to then find a simple article covering how to properly read from an .env file in Go.&lt;/p&gt;

&lt;p&gt;This is a super quick tutorial from someone who just learned it as well. Enjoy!&lt;/p&gt;

&lt;h1&gt;
  
  
  Code Example
&lt;/h1&gt;

&lt;p&gt;Let's start by importing needed dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c"&gt;// Needed for terminal printing, similar to "console.log" in Node.js&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="c"&gt;// Helpful for logging errors&lt;/span&gt;
    &lt;span class="s"&gt;"log"&lt;/span&gt;
    &lt;span class="c"&gt;// Needed for accessing .env file&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
    &lt;span class="c"&gt;// Needed for importing/loading .env file&lt;/span&gt;
    &lt;span class="s"&gt;"github.com/joho/godotenv"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then let's write a type structure, I used Human for simplicity's sake. Any human needs to have a name and a secret age. After all, isn't there a saying that it is inappropriate to ask people about their age?&lt;/p&gt;

&lt;p&gt;I also simplified age to a string so that someone could be "20" or "twenty" years old.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;human&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;Age&lt;/span&gt;  &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets start writing our main.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Creates a variable 'creds' in memory and assigns&lt;/span&gt;
    &lt;span class="c"&gt;// it to an object with type 'human'&lt;/span&gt;
    &lt;span class="n"&gt;creds&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;human&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;// Given that name is stored as "NAME_TOKEN=Jade" &amp;amp; age is&lt;/span&gt;
        &lt;span class="c"&gt;// "AGE_SECRET_TOKEN=34", we now can ask Getenv to give us&lt;/span&gt;
        &lt;span class="c"&gt;// the value of a token based on the provided key.&lt;/span&gt;
        &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"NAME_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"AGE_SECRET_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Simply prints "Jade is 34 years old." to check&lt;/span&gt;
    &lt;span class="c"&gt;// that we correctly read from the .env file&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;creds&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" is "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;creds&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" years old."&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;If you were following with me until this point, you'd probably realize that running &lt;code&gt;go run [filename].go&lt;/code&gt; won't give much result. That is because right now we are trying to read from something we haven't imported yet! Let's fix this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Init is called right on top of main&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Loads the .env file using godotenv.&lt;/span&gt;
    &lt;span class="c"&gt;// Throws an error is the file cannot be found.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;godotenv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No .env file found"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what we have by putting all the little pieces together. Good luck, &lt;br&gt;
 and let me know if you need more clarification!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"log"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;

    &lt;span class="s"&gt;"github.com/joho/godotenv"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;human&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="n"&gt;Age&lt;/span&gt;  &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;godotenv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No .env file found"&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;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;creds&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;human&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"NAME_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"AGE_SECRET_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;creds&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" is "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;creds&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" years old."&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;
  
  
  The output
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jJ1A3u-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/egc7igfobw51ztr8imce.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jJ1A3u-A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/egc7igfobw51ztr8imce.png" alt='Terminal logs "Jade is 34 years old."'&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nPKCudV7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/bzr47frhmg7w17i22gw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nPKCudV7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/bzr47frhmg7w17i22gw9.png" alt="A black text divider" height="50%" width="50%"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  On a personal note
&lt;/h1&gt;

&lt;p&gt;For the first time I didn't let perfectionism consume me when writing something! This article, if I can call it that way, was meant more as a way for me to store notes than anything else. So if you have any feedback on how to improve the above code, do let me know and I will fix it!&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>notes</category>
    </item>
    <item>
      <title>Understanding Flexbox with Cats: Part 1 Basics</title>
      <dc:creator>Kate Efimova</dc:creator>
      <pubDate>Mon, 29 Jul 2019 05:44:14 +0000</pubDate>
      <link>https://forem.com/kefimochi/understanding-flexbox-with-cats-part-1-basics-1532</link>
      <guid>https://forem.com/kefimochi/understanding-flexbox-with-cats-part-1-basics-1532</guid>
      <description>&lt;p&gt;Everyone loves cats, right? They are adorable fluffy little beings that enjoy smashing things and not obeying anyone. Well, in this series we'll make an assumption that suddenly they will listen to all commands given the magical phrase, &lt;code&gt;display: flex;&lt;/code&gt;. "Understanding Flexbox with Cats" will use the analogy of &lt;code&gt;cats and boxes&lt;/code&gt; to teach concepts like the CSS box model, flexbox positioning, and provide some valuable tips on the use of containers. Please keep in mind that this series assumes that a reader already has some basic understanding of HTML and CSS.&lt;/p&gt;

&lt;p&gt;In part one, we will mainly focus on a reader's thorough understanding of how flexbox positioning works with multiple containers. This part is for two types of people: those who never truly understood flexbox and those who love reading how someone can creatively use an analogy when connecting two seemingly unrelated things.&lt;/p&gt;

&lt;center&gt;~ Please enjoy this article full of kitten logic! ~&lt;/center&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%2Fkefimochi%2FFlexbox-with-cats%2Fblob%2Fmaster%2FMyCat.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%2Fkefimochi%2FFlexbox-with-cats%2Fblob%2Fmaster%2FMyCat.png%3Fraw%3Dtrue" alt="An illustration of a black cat staring at you"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  "Flexbox with Cats" Contests
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dev.to/kefimochi/understanding-flexbox-with-cats-part-1-basics-1532"&gt;Part 1: Flexbox basics&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Beginner-friendly introduction to CSS's box model and positioning of divs&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Part 2: Think in "boxes"

&lt;ul&gt;
&lt;li&gt;An article describing how to recognize containers("divs") when working with a provided design and how to implement the desired positioning.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Part 3: Advanced Flexbox and CSS

&lt;ul&gt;
&lt;li&gt;Covering everything from using flexbox in order to make a website responsive all the way to how to create your own designs. We'll also get to look at real-world implementations of everything learned throughout this series.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbzr47frhmg7w17i22gw9.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbzr47frhmg7w17i22gw9.png" alt="A black text divider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to "Cats and Boxes"
&lt;/h2&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F04tkt4ec6pmgu5zxv731.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F04tkt4ec6pmgu5zxv731.jpg" alt="Cat's face looking deeply into your soul from inside of a box"&gt;&lt;/a&gt;&lt;/p&gt;
Cat's face looking deeply into your soul from inside of a box



&lt;p&gt;Let's imagine a situation where suddenly you found yourself being responsible for three little kittens. As you see your apartment slowly turning into a disordered mess due to those tiny energized cats walking all over the place—and scratching on surfaces they shouldn't be scratching—you slowly begin to panic. What's a possible solution to all this chaos? 🤔&lt;/p&gt;

&lt;p&gt;If you thought about trying to limit cats' space, you were correct! Just like in real life, we first have to set up a &lt;code&gt;box&lt;/code&gt;(also known as a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element) before putting any &lt;code&gt;cats&lt;/code&gt;(representation for any content, like images, text, lists, etc) into it. It would not make sense to first put kittens on the ground and then add a box on top of them, so try to avoid doing that when using flexbox too!&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up a Default Box
&lt;/h2&gt;

&lt;p&gt;Keeping that in mind, lets set up our HTML. Right now it is important to notice that &lt;code&gt;cats&lt;/code&gt;(3 images) were already placed in a &lt;code&gt;box&lt;/code&gt;(div with a class of &lt;code&gt;cat-box&lt;/code&gt;). You might wonder why are they all gathered in one place, well, it's time to introduce some kitten logic! &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/KateEfimova/embed/NQxNVp?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You see— as their default behavior, cats &lt;em&gt;love&lt;/em&gt; to cuddle. Especially considering that those kittens are in an unfamiliar environment where they were just placed seconds ago after ruining an entire apartment. They're not sure how to act, so they would just always stay close next to each other in the top left corner, warming each other up and feeling safe.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgpa56eyvjawy3zy42y1o.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgpa56eyvjawy3zy42y1o.png" alt="All cat images are inside of a div container and are aligned in the top left corner"&gt;&lt;/a&gt;&lt;/p&gt;
All cat images are inside of a div container and are aligned in the top left corner



&lt;h2&gt;
  
  
  Introducing Flexbox
&lt;/h2&gt;

&lt;p&gt;Cats generally consider themselves to be of high esteem, so in order for them to obey, we'll have to give a command of &lt;code&gt;display: flex;&lt;/code&gt; to the box kittens are in. Someone might wonder, "why not give it to every single cat individually instead?" Well, this is because the box holds higher authority over cats due to restricting the space they can move in! And cats — being proud aristocrats — &lt;em&gt;only&lt;/em&gt; listen to higher authority. Nothing will happen if you'll try to add &lt;code&gt;display: flex;&lt;/code&gt; to any of the cat images; they're very stubborn (More on the &lt;code&gt;why&lt;/code&gt; later, it is related to &lt;code&gt;thinking outside of the box&lt;/code&gt;! &lt;em&gt;pun intended&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;What display flex will do is tell cat images to position themselves in a row and start listening to other commands. As you just thought, they were originally positioned in a row, so the only difference that will be noticed is a lack of space between pictures.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg1ovqqyv19e7vxvwemda.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg1ovqqyv19e7vxvwemda.png" alt="On the left there's a small space between pictures of cats vs on the right there's no space between cat pictures"&gt;&lt;/a&gt;&lt;/p&gt;
On the left there's a small space between pictures of cats vs on the right there's no space between cat pictures due to added `display: flex;`



&lt;p&gt;Now, let's pretend that a perfectionist friend comes over to your apartment, and wants to align all kittens and the box according to the center of that room. There are two directions we'll have to align them in: horizontal(main axis) and vertical(cross axis). Here's a well-done visual representation of the axis:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg27l033hgkwruldy3wlq.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg27l033hgkwruldy3wlq.jpg" alt="Cross(x) vs main(y) Axis when it comes to web development"&gt;&lt;/a&gt;&lt;/p&gt;
Cross(x) vs main(y) Axis when it comes to web development



&lt;p&gt;First, let's align them according to y-axis by attaching &lt;code&gt;align-items: center;&lt;/code&gt; to the &lt;code&gt;.cat-box&lt;/code&gt;. Then, let's also position them correctly on x-axis by adding &lt;code&gt;justify-content: center;&lt;/code&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1fe1y0tiu2ir8c56latc.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1fe1y0tiu2ir8c56latc.png" alt="Cats that are aligned centrally on the y-axis"&gt;&lt;/a&gt;&lt;/p&gt;
Cats that are aligned centrally on the y-axis



&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frpw3nrm0gu7o6cl08iks.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frpw3nrm0gu7o6cl08iks.png" alt="Cats that are aligned centrally on both y-axis and x-axis"&gt;&lt;/a&gt;&lt;/p&gt;
Cats that are aligned centrally on both y-axis and x-axis



&lt;p&gt;At this point, these CSS properties were added to &lt;code&gt;.cat-box&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;
  display: flex;
  align-items: center;
  justify-content: center;
&lt;/pre&gt;

&lt;p&gt;As you have probably noticed, even though cats are now aligned centrally, the box holding them is still not where it needs to be. The perfectionist friend gets upset and, not trusting you anymore with such an "&lt;em&gt;important&lt;/em&gt;" responsibility, starts to mess with cat positioning himself.&lt;/p&gt;

&lt;p&gt;Here's what he gets by trying to align all containers on the &lt;code&gt;body&lt;/code&gt; of CSS by attaching the same properties we just attached to &lt;code&gt;.cat-box&lt;/code&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn2kvatihe14xrwyv9rw8.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fn2kvatihe14xrwyv9rw8.png" alt="Despite using same properties on the  raw `body` endraw , the box only gets aligned centrally according to x-axis"&gt;&lt;/a&gt;&lt;/p&gt;
Despite using same properties on the `body`, the box only gets aligned centrally according to x-axis



&lt;p&gt;What he doesn't yet realize is that all furniture and other items like Nintendo Switch and MacBook Pro were suddenly centered in the apartment too, which is definitely an unwanted behavior! It is generally considered a bad practice to attach flexbox properties to the body.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fluue5r1h4yn4tc5o0k90.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fluue5r1h4yn4tc5o0k90.png" alt="A MacBook on the left of kittens and Nintendo Switch on the right of the kittens get aligned centrally on y-axis"&gt;&lt;/a&gt;&lt;/p&gt;
A MacBook on the left of kittens and Nintendo Switch on the right of the kittens get aligned centrally on y-axis



&lt;p&gt;So in order to align both kittens &lt;em&gt;and&lt;/em&gt; the box to the center of our screens, we'll have to create another &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; with a class of &lt;code&gt;.outer-container&lt;/code&gt; and wrap it around the existing content. Why do we need that? Let's dive deeper into why by breaking down an example!&lt;/p&gt;

&lt;p&gt;Take a look at this dev.to component that can be found on their main page. On the right side is a demonstration of how many containers(boxes) are currently used to make it work. Notice how they're nested — meaning inside each other. Light color that looks similar to a highlighter is there to portray inner padding of each 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0yn25gekow9k33tjrxnl.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0yn25gekow9k33tjrxnl.png" alt="Dev.to components with navigation links is broken down to several colored boxes"&gt;&lt;/a&gt;&lt;/p&gt;
Dev.to components with navigation links is broken down into several colored boxes



&lt;p&gt;All flexbox manipulations are &lt;strong&gt;always&lt;/strong&gt; one layer deep, meaning it only affects closest child boxes. For example, the purple container can only manipulate three inner containers but not any &lt;code&gt;&amp;lt;h&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; elements inside of them. Whereas the the dark blue container has an ability to do something with it's anchors by attaching flexbox into itself(notice that &lt;code&gt;display: flex&lt;/code&gt; would be attached to the &lt;em&gt;container&lt;/em&gt; when you want to manipulate elements inside of it).&lt;/p&gt;

&lt;p&gt;If you haven't noticed the pattern yet: we wanted to align kittens =&amp;gt; gave a command to their closest outer box; desired to manipulate that same box =&amp;gt; created a container outside of it that wraps the whole content. You would not be able to control cats from the &lt;code&gt;.outer-container&lt;/code&gt;. Thus, try to remember a phrase &lt;strong&gt;think outside of the box&lt;/strong&gt; since if you want to manipulate certain elements, you need to find the closest outer container in order to assign flexbox properties to it.&lt;/p&gt;

&lt;p&gt;Keeping that in mind, the reason why all anchors in a dark blue container are positioned in a column is because they were given a flexbox property of &lt;code&gt;flex-direction: column;&lt;/code&gt; through inheriting it from their purple parent container. Take a look at what happens to this dev.to component if flexbox direction is changed to row on the purple container. Can you still recognize the same boxes without lines and highlights? 😉&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzsmqxhuzmi79w3h0qlv6.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzsmqxhuzmi79w3h0qlv6.png" alt="Components look broken when flex-direction of the most outer container is changed to row"&gt;&lt;/a&gt;&lt;/p&gt;
Components look broken when flex-direction of the most outer container is changed to row



&lt;p&gt;Going back to the visual example with cats, it now supposed to make sense why we need an extra wrapping container: otherwise there's no way to control the box that holds the cats. All there's left to do is add an extra &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; on HTML, give it a class, declare flexbox central positioning and add a &lt;em&gt;limited&lt;/em&gt; size on that class. There are ways of making a container change it's size according to the stretching and squishing of content inside of it but we'll be diving into it more in Part 2 and 3 of this series. You're free to take a look at the finished code on this CodePen:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/KateEfimova/embed/JgbEGr?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy3ajsb89jf9igo06s0iy.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy3ajsb89jf9igo06s0iy.png" alt="Both cats and the box are positing in the center of the screen"&gt;&lt;/a&gt;&lt;/p&gt;
Both cats and the box are positing in the center of the screen



&lt;p&gt;We can have some fun playing with various others &lt;code&gt;justify-content&lt;/code&gt;, here's a visual representation of how it changes things using this gif:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd1kvha5eo6zlu2zmchyi.gif" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd1kvha5eo6zlu2zmchyi.gif" alt="A gif showing properties like  raw `justify-content` endraw  flex-start, flex-end, space-evenly and space-between"&gt;&lt;/a&gt;&lt;/p&gt;
A gif showing properties like `justify-content` flex-start, flex-end, space-evenly and space-between



&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgh7fdb1a4rssmr1c368a.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgh7fdb1a4rssmr1c368a.png" alt="Demonstrates difference between various  raw `justify-content` endraw  properties"&gt;&lt;/a&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbzr47frhmg7w17i22gw9.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbzr47frhmg7w17i22gw9.png" alt="A black text divider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hopefully an analogy of using &lt;code&gt;cats and boxes&lt;/code&gt; helped you to grasp concepts of flexbox better. All terminology was on purpose simplified to focus solely on the importance of understanding. In addition, I'd love to hear your thoughts on Part 1: what did go well as well as what could have been done better? Do keep in mind that it is my &lt;em&gt;first ever&lt;/em&gt; article written! Here's a repository with markdown of this article, you're welcome to create any and all pull requests!&lt;br&gt;
&lt;a href="https://github.com/kefimochi/Flexbox-with-cats/blob/master/Part%201/Basics.md" rel="noopener noreferrer"&gt;https://github.com/kefimochi/Flexbox-with-cats/blob/master/Part%201/Basics.md&lt;/a&gt;&lt;/p&gt;

&lt;center&gt;~ Thank you for reading! ~&lt;/center&gt;

</description>
      <category>flexbox</category>
      <category>css</category>
      <category>cats</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
