<?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: Divyesh Kamalanaban</title>
    <description>The latest articles on Forem by Divyesh Kamalanaban (@divyeshkamalanaban).</description>
    <link>https://forem.com/divyeshkamalanaban</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%2F712396%2F90378f4a-2250-437a-9556-81d539c2d327.png</url>
      <title>Forem: Divyesh Kamalanaban</title>
      <link>https://forem.com/divyeshkamalanaban</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/divyeshkamalanaban"/>
    <language>en</language>
    <item>
      <title>JavaScript weather app for absolute beginners</title>
      <dc:creator>Divyesh Kamalanaban</dc:creator>
      <pubDate>Fri, 12 Nov 2021 07:56:39 +0000</pubDate>
      <link>https://forem.com/divyeshkamalanaban/javascript-weather-app-for-absolute-beginners-3nfi</link>
      <guid>https://forem.com/divyeshkamalanaban/javascript-weather-app-for-absolute-beginners-3nfi</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I know, calling APIs and fetching them can be really tough for beginners. It is an absolute pain in the neck for absolute beginners. However, I'll try to explain all about APIs through a really decent web application, a simple weather app.&lt;/p&gt;

&lt;p&gt;This may seem tough, but actually it's easier than it looks. &lt;/p&gt;

&lt;p&gt;I will be using AJAX to call APIs and fetch information from them, so this might seem outdated, but to get a good idea about API calling, this is a good way to start.&lt;/p&gt;

&lt;p&gt;You need to know some Javascript to continue with this tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are APIs actually?
&lt;/h2&gt;

&lt;p&gt;APIs or Application Programming Interface acts like an intermediate between server and the client that brings or &lt;em&gt;fetches&lt;/em&gt; information from the server to the client.&lt;/p&gt;

&lt;p&gt;With that data, you can create applications like a weather app, which without APIs is practically impossible. &lt;/p&gt;

&lt;p&gt;Why? Because you need to have satellites and huge amount of system to harness the information from satellites, which contain the forecast data.&lt;/p&gt;

&lt;p&gt;Now that you know what an API actually is, let's take a quick glance at what we're going to do get data today!&lt;/p&gt;

&lt;p&gt;I am not going to focus much on UI today, since it's all about logic for today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Agenda for today:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Get your API key from &lt;a href="https://openweathermap.org"&gt;https://openweathermap.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Make a &lt;code&gt;XHR request&lt;/code&gt; to the &lt;a href="https://openweathermap.org"&gt;https://openweathermap.org&lt;/a&gt; server and get the JSON file.&lt;/li&gt;
&lt;li&gt;Get the required info from JSON file.&lt;/li&gt;
&lt;li&gt;Show the data to users.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I recommend you use the console for showing the data, because showing the information in screen isn't agile and effective.&lt;/p&gt;

&lt;p&gt;With that said, let's get our hands dirty.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making a XHR Request
&lt;/h2&gt;

&lt;p&gt;What on earth is XHR? XHR stands for XML HTTP Request. From the name, you can find out it's a HTTP request for XML. &lt;/p&gt;

&lt;p&gt;Irony that we're using it in Javascript? Nope.&lt;/p&gt;

&lt;p&gt;Actually, we're using AJAX method as told before. AJAX stands for Asynchronous JavaScript and XML. Since this method is used in both JS and XML, XHR request becomes relevant to JavaScript too.&lt;/p&gt;

&lt;p&gt;The thing that actually is ironical is that we're repeating the word 'Request'.&lt;/p&gt;

&lt;p&gt;Till now, you have learnt synchronous JavaScript, which executes step by step or line by line.&lt;/p&gt;

&lt;p&gt;But when it comes to APIs, you'll use asynchronous Javascript, which doesn't wait for an action or a function to get over. &lt;/p&gt;

&lt;p&gt;So, this will heavily reduce wait times, which in turn doesn't annoy the user.&lt;/p&gt;

&lt;p&gt;Coming back to the request, it is being heavily used in AJAX. You could say that XHR is a huge part of AJAX.&lt;/p&gt;

&lt;p&gt;Now, let's create a &lt;code&gt;function&lt;/code&gt; namely &lt;code&gt;getweather()&lt;/code&gt;. Pass &lt;code&gt;e&lt;/code&gt; (preferably) inside the parameters. This will be used to troubleshoot errors.&lt;/p&gt;

&lt;p&gt;Now, let's create a constant &lt;code&gt;xhr&lt;/code&gt; with value &lt;code&gt;new XMLhttpRequest()&lt;/code&gt;. the &lt;code&gt;new&lt;/code&gt; keyword is used to create an &lt;code&gt;object&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep dive into Objects
&lt;/h3&gt;

&lt;p&gt;An &lt;code&gt;object&lt;/code&gt; is a data type that's used in OOP (Object Oriented Programming). Consider an &lt;code&gt;object&lt;/code&gt; like a real life object, which has properties.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;let car =  new object();&lt;/code&gt;. Now, let's define the properties of this object, &lt;code&gt;car&lt;/code&gt;.&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;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Challenger&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;manufacturer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dodge&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Seems easy, right? So, I correlated a real life object, which is a Dodge Challenger red car with a JavaScript Object, which has these properties of real life car defined.&lt;/p&gt;

&lt;p&gt;There are ton of use cases. Imagine you are creating a user database. There are about a 100 users. So, you can create a &lt;code&gt;people&lt;/code&gt; object to define the basic properties of your users.&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;function&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emailid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;address&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;&lt;em&gt;Notice the use of &lt;code&gt;this&lt;/code&gt; keyword. The &lt;code&gt;this&lt;/code&gt; keyword refers to &lt;code&gt;User&lt;/code&gt; in this function or context. The value of &lt;code&gt;this&lt;/code&gt; keyword changes with context or the function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What I showed you before is creating a simple object, used for generally theoretical purposes.&lt;/p&gt;

&lt;p&gt;What I showed you is a constructor function, which helps us assign the properties of &lt;code&gt;User&lt;/code&gt; to those 3 variables mentioned as parameters.&lt;/p&gt;

&lt;p&gt;So, let's create a new user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let Ken  = new User('Ken', 'ken@random.com', 'Times Square, NYC');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we've created a new user with name Ken, email '&lt;a href="mailto:ken@random.com"&gt;ken@random.com&lt;/a&gt;', and with his address as 'Times Square, NYC'.&lt;/p&gt;

&lt;p&gt;Now, we can create as many users as we want with a base &lt;code&gt;Object&lt;/code&gt; of &lt;code&gt;User&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This forms the crux of &lt;code&gt;OOP&lt;/code&gt;, which is an important part of probably every programming language.&lt;/p&gt;

&lt;p&gt;So, this knowledge is enough to help us call APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuing with XHR
&lt;/h2&gt;

&lt;p&gt;Now, let's use the &lt;code&gt;open()&lt;/code&gt; method (a function present inside an object).&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;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`https://api.openweathermap.org/data/2.5/weather?q=ANYCITYFORNOW&amp;amp;appid=YOURAPIKEY&amp;amp;units=metric`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;When it comes to APIs, there are a few methods that comes to use.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GET&lt;/li&gt;
&lt;li&gt;PUT&lt;/li&gt;
&lt;li&gt;POST &lt;/li&gt;
&lt;li&gt;DELETE&lt;/li&gt;
&lt;li&gt;PATCH&lt;/li&gt;
&lt;li&gt;HEAD&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These methods refer to these 5 operations respectively.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;READ&lt;/li&gt;
&lt;li&gt;UPDATE&lt;/li&gt;
&lt;li&gt;WRITE&lt;/li&gt;
&lt;li&gt;DELETE&lt;/li&gt;
&lt;li&gt;Partial Modifications&lt;/li&gt;
&lt;li&gt;Similar to GET, but provides response without body.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We'll be using GET, because we want to just read the data and obtain it from the server.&lt;/p&gt;

&lt;p&gt;I used template literals (backticks) for the API key, more on that later.&lt;/p&gt;

&lt;p&gt;So, after this, we'll use &lt;code&gt;xhr.onload()&lt;/code&gt; method. This accepts a callback function or a function that gets executed after &lt;code&gt;xhr.onload&lt;/code&gt; is done.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;xhr.onload()&lt;/code&gt; is simple to understand: After the request is done and you get the data, what should be done.&lt;/p&gt;

&lt;p&gt;Now in this function there are 2 conditions, for which we will be using &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;else&lt;/code&gt; statements.&lt;/p&gt;

&lt;p&gt;Take a look at this code:&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;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;200&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;responseText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;            
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Something went wrong.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the &lt;code&gt;this.status&lt;/code&gt; is the status code server returns after the request. 200 means the request is OK, so we've used 200 here.&lt;/p&gt;

&lt;p&gt;I've passed &lt;code&gt;data&lt;/code&gt; as the argument here, just in case to troubleshoot errors. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;responseText&lt;/code&gt; is the text that server provides after our request. We've to convert it into JSON, so that we can get the required data, therefore I used &lt;code&gt;JSON.parse()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Now, you can console log the &lt;code&gt;response&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;Try running the code, and see if it works. Works? nope.&lt;/p&gt;

&lt;p&gt;We didn't send the request yet! use &lt;code&gt;xhr.send()&lt;/code&gt; after the above code.&lt;/p&gt;

&lt;p&gt;Now open the console and check if it works. It should work. If it doesn't check the API link once more and see if you have substituted the right values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting the required values
&lt;/h2&gt;

&lt;p&gt;Now getting the required values is really simple. Take a look at the JSON and see the all the values closely. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;main&lt;/code&gt; JSON contains the current temperature, minimum temperature and maximum temperature.&lt;/p&gt;

&lt;p&gt;Let's store the temperature value in &lt;code&gt;temp&lt;/code&gt; variable.&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;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Console log it and see if it works. It works!&lt;/p&gt;

&lt;p&gt;Store the required values in respective variables and try console logging it. If all works, you have successfully done the API calling right!&lt;/p&gt;

&lt;p&gt;Now, take the input element of your webpage, and call it with its &lt;code&gt;id&lt;/code&gt; or &lt;code&gt;class&lt;/code&gt; by &lt;code&gt;document.getElementById&lt;/code&gt; or &lt;code&gt;document.getElementByClass&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Use the value property and substitute it in the link. Template literals lets you do this by adding &lt;code&gt;${value}&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;So, we have pretty much completed the API calling!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Making a simple CSS timeline for beginners!</title>
      <dc:creator>Divyesh Kamalanaban</dc:creator>
      <pubDate>Mon, 08 Nov 2021 12:58:19 +0000</pubDate>
      <link>https://forem.com/divyeshkamalanaban/making-a-simple-css-timeline-for-beginners-1ccg</link>
      <guid>https://forem.com/divyeshkamalanaban/making-a-simple-css-timeline-for-beginners-1ccg</guid>
      <description>&lt;h2&gt;
  
  
  A little bit of backstory
&lt;/h2&gt;

&lt;p&gt;While I was designing my own portfolio, I was thinking to create a dedicated timeline for it. Timelines always looked complicated, to be honest. While I searched for timelines across the internet, I came to know that there are multiple ways of creating CSS Timelines.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few ways to create timeline:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Using Flexboxes&lt;/li&gt;
&lt;li&gt;Using Grid&lt;/li&gt;
&lt;li&gt;Using an Unordered List (Seriously?)&lt;/li&gt;
&lt;li&gt;Positioning &lt;code&gt;divs&lt;/code&gt; using transforms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We'll be using grids to create a CSS timeline, which is probably the most beginner friendly ways to get started with CSS Timelines (I hope).&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the basic structure
&lt;/h2&gt;

&lt;p&gt;We'll start with some basic HTML to create a barebones structure for our Timeline.&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;section class="full-page"&amp;gt;
&amp;lt;!--This is the main container that contains the whole timeline.--&amp;gt;

&amp;lt;div class="timeline"&amp;gt;

          &amp;lt;!--Well, The reason for this div is to fill space. 
This space is technically used for keeping dates, 
but I didn't find the need for dates. However, I'll provide 
you the styling for dates, so that you can use it if you 
wanted to.--&amp;gt;
                  &amp;lt;div class="timeline-empty"&amp;gt;
                  &amp;lt;/div&amp;gt;

&amp;lt;!--This is the class where the timeline graphics are 
housed in. Note that we have timeline-circle 
here for that pointer in timeline.--&amp;gt;

               &amp;lt;div class="timeline-middle"&amp;gt;
                   &amp;lt;div class="timeline-circle"&amp;gt;&amp;lt;/div&amp;gt;
               &amp;lt;/div&amp;gt;
               &amp;lt;div class="timeline-component timeline-content"&amp;gt;
                &amp;lt;h3&amp;gt;HTML&amp;lt;/h3&amp;gt;
                &amp;lt;p&amp;gt;Some Text&amp;lt;/p&amp;gt;
           &amp;lt;/div&amp;gt;
                &amp;lt;div class="timeline-component timeline-content"&amp;gt;
                         &amp;lt;h3&amp;gt;CSS&amp;lt;/h3&amp;gt;
                         &amp;lt;p&amp;gt;Some Text.&amp;lt;/p&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div class="timeline-middle"&amp;gt;
                    &amp;lt;div class="timeline-circle"&amp;gt;&amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div class="timeline-empty"&amp;gt;
                &amp;lt;/div&amp;gt;

                &amp;lt;div class="timeline-empty"&amp;gt;
                &amp;lt;/div&amp;gt;

               &amp;lt;div class="timeline-middle"&amp;gt;
                   &amp;lt;div class="timeline-circle"&amp;gt;&amp;lt;/div&amp;gt;
               &amp;lt;/div&amp;gt;
               &amp;lt;div class=" timeline-component timeline-content"&amp;gt;
                &amp;lt;h3&amp;gt;Javascript&amp;lt;/h3&amp;gt;
                &amp;lt;p&amp;gt;Some Text.&amp;lt;/p&amp;gt;
           &amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;I have explained majority part of the code in the comment blocks in the above code, in case you felt it wasn't adequate enough, let me know in the comments below.&lt;/p&gt;

&lt;p&gt;The first half of making timeline is over. On to CSS!&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling the timeline.
&lt;/h2&gt;

&lt;p&gt;Right now, our timeline looks like 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fux99kqj8tvq8pnwof3j3.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%2Fuploads%2Farticles%2Fux99kqj8tvq8pnwof3j3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not a great thing to look at. So, we'll use CSS to make our timeline look cool.&lt;/p&gt;

&lt;p&gt;I've used Sass here, which you can see in the variables here, but there's no much deviation from regular CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.full-page{
/*I have used this to center the whole timeline on the screen.*/
  display: flex;
  align-items: center;
  justify-content: center;
}

/*The timeline container has a minimal width
than the main container to make text look more dressed up.*/
.timeline{
  width: 80%;
  height: auto;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/*This is the container for timeline content. Those are its
styling. The include statement is used in sass to copy 
a certain bunch of rules. This is related to 
styling and nothing to worry at your end.*/

.timeline-content{
  padding: 20px;
  @include neu-card; 
  margin-bottom: 20px;
  border-radius: 6px ;
}

/*Adding some margin for all components in
the timeline. The timeline content is used 
for text blocks exclusively.*/

.timeline-component{
  margin: 0px 20px 20px 20px;
}

/*This is where, I've added responsiveness. Before 
this I added display: flex to show it as an 
array of text blocks. But if the screen size is
 huge enough for a timeline, you can use media 
queries to add styles that are apt for larger 
screens, which is adding a timeline. 1fr 3px
1fr means that there will be 3 columns with 2 
columns equally sized with a column of width 3px
in the middle.
*/

@media screen and (min-width: 768px) {
  .timeline{
    display: grid;
    grid-template-columns: 1fr 3px 1fr;
  }

/*Adding the styles for the timeline line and pointer.*/

  .timeline-middle{
    position: relative;
    background-image: $linear-grad;
    width: 3px;
    height: 100%;
  }

/*Adding styles for that circle pointer. using
some transforms and positioning to keep it center*/
  .timeline-circle{
    position: absolute;
    top: 0;
    left: 50%;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background-image: $linear-grad;
    transform: translateX(-50%);

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

&lt;/div&gt;



&lt;p&gt;And marks the end of this code. The comments in the code block are hopefully helpful in explaining the code well to you.&lt;/p&gt;

&lt;p&gt;This is how my version of the code looks (You can find the pure CSS version in this embed, but the formatting is pretty messed:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Divyesh-K/embed/YzxLQNz?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Try resizing the result window, you'll see the magic for yourself.&lt;/p&gt;

&lt;p&gt;There might be much efficient ways to do the same thing (Using flexboxes), but since this is a tutorial oriented for beginners, I've used grids.&lt;/p&gt;

&lt;p&gt;Grids are really easy to understand comparatively. That's why I chose grids over flexboxes. &lt;/p&gt;

&lt;p&gt;However, if you need a flexbox version of this, there are ton of tutorials on the internet. Who knows, maybe I could create a flexbox version of this article soon!&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates.&lt;/p&gt;

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