<?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: Debojyoti Ghosh</title>
    <description>The latest articles on DEV Community by Debojyoti Ghosh (@gdebojyoti).</description>
    <link>https://dev.to/gdebojyoti</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%2F412711%2Fbc2924af-96e9-4df2-bdf0-dccf2ddec0b7.jpeg</url>
      <title>DEV Community: Debojyoti Ghosh</title>
      <link>https://dev.to/gdebojyoti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gdebojyoti"/>
    <language>en</language>
    <item>
      <title>The Strawberry Problem in ChatGPT</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Wed, 11 Sep 2024 13:16:04 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/the-strawberry-problem-in-chatgpt-k2k</link>
      <guid>https://dev.to/gdebojyoti/the-strawberry-problem-in-chatgpt-k2k</guid>
      <description>&lt;p&gt;Recently there has been an influx of memes showcasing how LLMs like Chat GPT cannot count the number of specific letters in certain words.&lt;/p&gt;

&lt;p&gt;Q: How many "r" does the word "strawberry" have?&lt;br&gt;
A: The word "strawberry" contains two "r"s.&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%2Fuploads%2Farticles%2Fb6pdgzohrm55ulcntj2b.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%2Fb6pdgzohrm55ulcntj2b.png" alt="ChatGPT failing to answer the count of "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The irony is that most LLMs can actually write you a great script in almost any programming language that will tell you with 100% accuracy exactly what letters are in any word and in what positions! 🤣&lt;/p&gt;

&lt;p&gt;Then why is it so bad at counting by itself?&lt;/p&gt;

&lt;h2&gt;
  
  
  How LLMs Work?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Training&lt;/strong&gt;&lt;br&gt;
LLMs are trained on diverse and extensive datasets. These datasets include books, websites, and other text sources. During these trainings, LLMs "learn" to predict the next word in a sentence based on the context of the words that came before it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inference&lt;/strong&gt;&lt;br&gt;
When you ask a question, an LLM will generate a response by predicting the next most likely word (or sequence of words) based on the input you've provided. LLMs don't "understand" in the way humans do. Instead, they generate text based on patterns that they have learnt during training.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the Mistake Happened?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Pattern matching&lt;/strong&gt;&lt;br&gt;
Sometimes, when processing a query, LLMs might prioritize generating a quick response that "seems correct". This is based on common patterns, rather than carefully analyzing every detail. In this case, Chat GPT likely relied on a quick assessment of the word "strawberry" without counting the "r" letters individually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tokenization and Probability&lt;/strong&gt;&lt;br&gt;
The underlying mechanism might have led to a mistake in counting. The word "strawberry" might have been tokenized in a way that didn't fully account for each letter in detail. The response was a result of a probabilistic guess that didn't equal to the exact count.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Tokenization?
&lt;/h2&gt;

&lt;p&gt;Tokenization is the process of breaking down a sequence of text into smaller units, called "tokens". They can be words, sub-words, or even individual characters - depending on the context and the tokenization approach used. It is a crucial preprocessing step that helps convert text into a format that can be numerically processed by LLMs.&lt;/p&gt;

&lt;p&gt;In this example, Chat GPT seems to have used "subword tokenization". As a result the word "strawberry" might have been split into "straw" and "berry". Each part was then treated as its own unit. This helps the model recognize patterns like "straw" and "berry" that are seen in other words ("straw" in "strawman," "berry" in "blueberry").&lt;/p&gt;

&lt;p&gt;However, since each subword was handled separately, it could have subtly affected the precision of the letter count. Instead of analyzing "strawberry" as a whole, Chat GPT seems to have focused on the tokenized subwords, leading to a miscount of the "r"s, especially if the internal logic wasn't careful about reassembling the entire word.&lt;/p&gt;

&lt;p&gt;In other words, it seems like the answer was based on a quick "glance" at one part of the word (like "berry") and not both parts combined.&lt;/p&gt;

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

&lt;p&gt;In tasks like counting or basic arithmetic, where precision is required, LLMs can sometimes make errors because those tasks aren't they were primarily designed to excel at. Hence, you may have to double check the result yourself, especially in situations where accuracy is critical.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>todayisearched</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Bubble Sort, Selection Sort, Insertion Sort | Data Structures &amp; Algorithms in JavaScript</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Mon, 02 Sep 2024 21:44:32 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/bubble-sort-selection-sort-insertion-sort-data-structures-algorithms-in-javascript-8ff</link>
      <guid>https://dev.to/gdebojyoti/bubble-sort-selection-sort-insertion-sort-data-structures-algorithms-in-javascript-8ff</guid>
      <description>&lt;p&gt;Sorting algorithms are the backbone of many computational tasks, playing a crucial role in organizing data for efficient access and processing. Whether you're a beginner just starting to explore the world of algorithms or a seasoned developer looking to refresh your knowledge, understanding these fundamental sorting techniques is essential. In this post, we'll explore some of the more basic sorting algorithms - Bubble Sort, Selection Sort, and Insertion Sort.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bubble Sort
&lt;/h2&gt;

&lt;p&gt;Bubble Sort is a simple, comparison-based sorting algorithm. It repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order. This process continues until no more swaps are needed, indicating that the list is sorted. While easy to understand and implement, Bubble Sort is inefficient for large datasets, making it suitable mainly for educational purposes and small data sets.&lt;/p&gt;

&lt;p&gt;Bubble Sort has a time complexity of &lt;strong&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/strong&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="c1"&gt;// a random array of 20 numbers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inputArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;67&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;56&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;67&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;56&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bubbleSort&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="c1"&gt;// loop n times&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;n&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="c1"&gt;// loop through all n-1 pairs&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;j&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;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&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="c1"&gt;// if a &amp;gt; b, swap; else do nothing&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&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;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&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;return&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Input:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;inputArray&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ouput:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;bubbleSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputArray&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Selection Sort
&lt;/h2&gt;

&lt;p&gt;Selection Sort is a straightforward, comparison-based sorting algorithm. It works by dividing the list into a sorted and an unsorted region. It repeatedly selects the smallest (or largest) element from the unsorted region and swaps it with the first unsorted element, gradually growing the sorted region. Selection Sort is not the most efficient for large datasets but is easy to understand and has the advantage of minimizing the number of swaps.&lt;/p&gt;

&lt;p&gt;Selection Sort has a time complexity of &lt;strong&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/strong&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="c1"&gt;// a random array of 20 numbers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inputArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;67&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;56&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;67&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;56&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;selectionSort&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="c1"&gt;// loop n times&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;n&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="c1"&gt;// start from i'th position&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lowestNumberIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&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;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&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="c1"&gt;// identify lowest number&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;lowestNumberIndex&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;lowestNumberIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// swap the lowest number with that in i'th position&lt;/span&gt;
    &lt;span class="kd"&gt;const&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;sortedArray&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="nx"&gt;sortedArray&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="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;lowestNumberIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;lowestNumberIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Input:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;inputArray&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ouput:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;selectionSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputArray&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Insertion Sort
&lt;/h2&gt;

&lt;p&gt;Insertion Sort is an intuitive, comparison-based sorting algorithm that builds the final sorted list one element at a time. It works by taking elements from the unsorted portion of the list and inserting them into their correct position within the sorted portion. Insertion Sort is efficient for small datasets or nearly sorted data and is often used in practical applications as a simpler alternative to more complex algorithms.&lt;/p&gt;

&lt;p&gt;Insertion Sort has a time complexity of &lt;strong&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/strong&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;insertionSort&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="c1"&gt;// loop n times, starting at index 1&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;1&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;n&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="c1"&gt;// start at index 1&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;comparedNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;tempIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;

    &lt;span class="c1"&gt;// compare with previous numbers (right to left)&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;j&lt;/span&gt; &lt;span class="o"&gt;=&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;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;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;j&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="c1"&gt;// if number in current index is larger than compared number, swap&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;comparedNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tempIndex&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nx"&gt;sortedArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;comparedNumber&lt;/span&gt;
        &lt;span class="nx"&gt;tempIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;j&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="c1"&gt;// OPTIONAL: else exit&lt;/span&gt;
        &lt;span class="k"&gt;break&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;return&lt;/span&gt; &lt;span class="nx"&gt;sortedArray&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Input:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;inputArray&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ouput:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;insertionSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputArray&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;While basic sorting algorithms like Bubble Sort, Selection Sort, and Insertion Sort may not be the most efficient for large datasets, they offer a great foundation for understanding algorithm design. If you found this post helpful, I'd love to hear your thoughts. Drop a comment below, share your insights, or ask any questions you have - I will try my best to answer them.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Grid Layout: The Ultimate Guide for Beginners</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Sun, 01 Sep 2024 14:39:52 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/grid-layout-the-ultimate-guide-for-beginners-3ek8</link>
      <guid>https://dev.to/gdebojyoti/grid-layout-the-ultimate-guide-for-beginners-3ek8</guid>
      <description>&lt;p&gt;Welcome back to your CSS adventure! Today, we're diving into one of the most powerful tools in your web design arsenal: CSS Grid Layout. Think of it as the Swiss Army knife of layout techniques - versatile, precise, and capable of transforming your web pages into beautifully organized masterpieces. Ready to grid and bear it? Let's go!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxto711l92fqes76ep8k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxto711l92fqes76ep8k.png" alt="Leo DiCaprio Cheers meme celebrating the success of creating a complex CSS Grid layout with minimal effort" width="612" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is CSS Grid Layout?
&lt;/h2&gt;

&lt;p&gt;Imagine you're playing a game of Tetris, but instead of stacking random blocks, you get to decide where everything goes. That's basically what CSS Grid does! It allows you to create complex, grid-based layouts that are both flexible and easy to manage. Whether you're working on a basic two-column layout or a full-blown magazine-style page, CSS Grid has got your back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use CSS Grid?
&lt;/h2&gt;

&lt;p&gt;Before Grid, web developers had to rely on clunky methods like floats, tables, or even nested divs to create layouts. It was like trying to build a Lego castle with only square blocks. But with CSS Grid, you get all the pieces you need to create something truly spectacular. Here's why you'll love it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility&lt;/strong&gt;: Create any layout you can dream of, from simple to complex.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Precision&lt;/strong&gt;: Control over spacing, alignment, and order with minimal effort.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity&lt;/strong&gt;: Clean, readable code that's easy to maintain and modify.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setting Up Your Grid: The Basics
&lt;/h2&gt;

&lt;p&gt;Let's start with the basics. To create a grid, you need a grid container and some grid items. The container is where the magic happens, and the items are the elements that get placed on the grid.&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;class=&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-item"&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&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"grid-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&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-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&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-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;4&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;Now, let's turn that container into a grid in your CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.grid-item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#007BFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;h2&gt;
  
  
  Understanding the Grid Properties
&lt;/h2&gt;

&lt;p&gt;Let's break it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;display: grid&lt;/code&gt;: This turns your container into a &lt;em&gt;grid&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grid-template-columns: repeat(2, 1fr)&lt;/code&gt;: This creates two equal-width columns. &lt;code&gt;1fr&lt;/code&gt; is a flexible unit that takes up &lt;em&gt;one part of the available space&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gap: 10px&lt;/code&gt;: This adds a 10px &lt;em&gt;gap between your grid items&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Placing Items on the Grid: You're the Boss
&lt;/h2&gt;

&lt;p&gt;Now that we have our grid, let's get fancy with how we place items. With CSS Grid, you can specify exactly where you want each item to go, like a master strategist planning the ultimate game board.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.grid-item&lt;/span&gt;&lt;span class="nd"&gt;:first-child&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;grid-column&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="m"&gt;3&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;In this example, the first grid item spans across two columns, while the rest stay neatly in their lanes. You can place items anywhere in the grid by defining their start and end points with grid-column and grid-row. It's like being able to park your car diagonally in a parking lot - because you can!&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Grid Techniques: Unleash Your Inner Architect
&lt;/h2&gt;

&lt;p&gt;Ready to take things up a notch? CSS Grid isn't just about placing items in boxes; it's about creating entire layouts with precision and ease.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Nested Grids
&lt;/h3&gt;

&lt;p&gt;Think of it as grids within grids - an inception of layout possibilities.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.nested-grid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&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, &lt;code&gt;.nested-grid&lt;/code&gt; is a grid item inside the main grid but also a grid container itself, allowing you to create even more complex layouts.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Auto-Fill and Auto-Fit
&lt;/h3&gt;

&lt;p&gt;Want your grid to adapt based on the available space? Meet &lt;code&gt;auto-fill&lt;/code&gt; and &lt;code&gt;auto-fit&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.grid-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;150px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&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;This setup automatically creates as many columns as possible that are at least 150px wide. Perfect for responsive designs where you want your content to adjust gracefully, like a cat always landing on its feet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;CSS Grid is the ultimate tool for creating layouts that are both powerful and flexible. It might seem a bit daunting at first, but once you get the hang of it, you'll wonder how you ever lived without it. With Grid, you're not just building a webpage; you're crafting a visually stunning, well-organized masterpiece.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>beginners</category>
      <category>grid</category>
    </item>
    <item>
      <title>Flexbox 101: A Beginner's Guide to Flexible Layouts</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Sat, 31 Aug 2024 10:40:59 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/flexbox-101-a-beginners-guide-to-flexible-layouts-4j5a</link>
      <guid>https://dev.to/gdebojyoti/flexbox-101-a-beginners-guide-to-flexible-layouts-4j5a</guid>
      <description>&lt;p&gt;So, you've dipped your toes into the world of CSS, and now you're ready to tackle layouts. Fantastic! But let's be honest - dealing with layouts can sometimes feel like trying to solve a Rubik's Cube blindfolded. That's where Flexbox swoops in, your new best friend for creating flexible, responsive layouts with less hassle and more ease. Let's dive into the magical world of Flexbox and get those boxes in order!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqyxp2kasbnqwiy12p3la.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqyxp2kasbnqwiy12p3la.png" alt="Surprised Pikachu meme highlighting the ease of solving complex CSS layout issues with Flexbox" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Flexbox anyway?
&lt;/h2&gt;

&lt;p&gt;Before we start flexing, let's get one thing straight: Flexbox is short for "Flexible Box Layout." It's a CSS layout module that helps you distribute space and align items within a container - even if their size is unknown or dynamic. In other words, Flexbox is like a super-organized friend who knows how to arrange a messy room into perfect order, no matter how much stuff you have.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flex Containers and Flex Items
&lt;/h2&gt;

&lt;p&gt;Flexbox works its magic with two key players: &lt;strong&gt;flex containers&lt;/strong&gt; and &lt;strong&gt;flex items&lt;/strong&gt;. The flex container is the parent element, and all the children inside it automatically become flex items. Imagine the container as a box, and all the items inside it as the flexible contents you want to arrange.&lt;/p&gt;

&lt;p&gt;Here's a quick example:&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;class=&lt;/span&gt;&lt;span class="s"&gt;"flex-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;"flex-item"&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&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&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;"flex-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&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;And the CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.flex-item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#007BFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&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;h2&gt;
  
  
  Flexbox Properties: The Secret Sauce
&lt;/h2&gt;

&lt;p&gt;Now that we've set up our flex container, let's sprinkle in some Flexbox properties to see the magic happen.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;flex-direction&lt;/code&gt;: The Way Things Flow
&lt;/h3&gt;

&lt;p&gt;Flexbox lets you control the direction in which your items are laid out. By default, items are arranged in a row, but you can easily switch things up with &lt;code&gt;flex-direction&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Items arranged horizontally */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Want to stack them vertically? Easy!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Items arranged vertically */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. &lt;code&gt;justify-content&lt;/code&gt;: Aligning Like a Pro
&lt;/h3&gt;

&lt;p&gt;Need to control the space between your items? &lt;code&gt;justify-content&lt;/code&gt; has got you covered. It aligns your items horizontally along the &lt;strong&gt;main axis&lt;/strong&gt; (the one defined by &lt;code&gt;flex-direction&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Items spread out with space in between */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other options include &lt;code&gt;flex-start&lt;/code&gt;, &lt;code&gt;flex-end&lt;/code&gt;, &lt;code&gt;center&lt;/code&gt;, &lt;code&gt;space-around&lt;/code&gt;, and &lt;code&gt;space-evenly&lt;/code&gt;. Each one offers a different way to distribute space.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;code&gt;align-items&lt;/code&gt;: Vertical Alignment Made Easy
&lt;/h3&gt;

&lt;p&gt;While &lt;code&gt;justify-content&lt;/code&gt; handles the horizontal, &lt;code&gt;align-items&lt;/code&gt; takes care of the vertical alignment (or &lt;strong&gt;cross axis&lt;/strong&gt;). It's perfect for &lt;em&gt;centering items&lt;/em&gt; without needing to fiddle with margins.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Items are centered vertically */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also align them at the start or end of the container with &lt;code&gt;flex-start&lt;/code&gt; or &lt;code&gt;flex-end&lt;/code&gt; respectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;code&gt;flex-wrap&lt;/code&gt;: When Things Get Cramped
&lt;/h3&gt;

&lt;p&gt;What happens when your flex items overflow the container? Enter &lt;code&gt;flex-wrap&lt;/code&gt;, the property that lets your items wrap onto multiple lines rather than squishing into oblivion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Items wrap to the next line */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just like that, your items get a cozy new line if they run out of space!&lt;/p&gt;

&lt;h2&gt;
  
  
  Responsive Design with Flexbox
&lt;/h2&gt;

&lt;p&gt;One of Flexbox's superpowers is making responsive design a breeze. Imagine you want to create a layout where items re-arrange themselves based on the screen size. Flexbox handles this effortlessly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.flex-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-around&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.flex-item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Flexible items with a minimum width */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this setup, each &lt;code&gt;.flex-item&lt;/code&gt; takes up at least 200px, but flexes to fill the available space. On smaller screens, they'll automatically wrap to the next line, keeping everything neat and tidy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Flexbox is like the Swiss Army knife of CSS layouts - powerful, versatile, and ready to tackle any challenge. With just a few lines of code, you can create layouts that are flexible, responsive, and easy to maintain.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>beginners</category>
      <category>flexbox</category>
    </item>
    <item>
      <title>CSS Layout Techniques - Floats, Clears, and Legacy Layouts: The Old School Cool</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Sat, 17 Aug 2024 05:18:53 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/css-layout-techniques-floats-clears-and-legacy-layouts-the-old-school-cool-2apj</link>
      <guid>https://dev.to/gdebojyoti/css-layout-techniques-floats-clears-and-legacy-layouts-the-old-school-cool-2apj</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
This article is part of a larger series that is available on my own website. &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;Click here to know more about CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcome to a blast from the past! Before Flexbox and Grid swept in like the superheroes of modern web design, there was a time when floats and clears ruled the CSS universe. If you're a web design newbie, you might be wondering, "What on earth are floats and clears, and why should I care?" Well, buckle up, because we're about to take a nostalgic trip through CSS history.&lt;/p&gt;

&lt;p&gt;Spoiler: you might find some cool tricks to use today!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6e6ghgeczy23x9c2ursm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6e6ghgeczy23x9c2ursm.png" alt="Distracted Boyfriend meme showing the boyfriend being distracted by modern CSS layout techniques like Flexbox &amp;amp; Grid while ignoring legacy techniques like floats &amp;amp; clears" width="750" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Floats: The Original Layout Trickster
&lt;/h2&gt;

&lt;p&gt;Imagine float as the rebellious teenager of the CSS world - always breaking out of the line and causing a bit of chaos. Floats were originally designed to wrap text around images, but clever developers quickly realized they could use them to create layouts too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;left&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15px&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;In the example above, &lt;code&gt;float: left;&lt;/code&gt; makes the image "float" to the left, allowing text to wrap around it. Floats were a popular choice for creating multi-column layouts before Flexbox and Grid came along. However, they can be a bit finicky and prone to causing layout issues if not used carefully.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clears: The Peacekeepers
&lt;/h2&gt;

&lt;p&gt;Floats might have been a bit rebellious, but clears were their peacekeepers. The clear property is like the mediator that steps in to resolve the chaos floats might create. If you're using floats and find that elements are overlapping or not behaving as expected, clear can help.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.clearfix&lt;/span&gt;&lt;span class="nd"&gt;::after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;both&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;By adding a &lt;code&gt;clearfix&lt;/code&gt; class with the above CSS, you ensure that any floated elements are contained within their parent container. It's a nifty way to prevent those annoying layout glitches where elements seem to float off into the abyss.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Legacy Layout Techniques: A Retro Revival
&lt;/h2&gt;

&lt;p&gt;Before Flexbox and Grid stole the spotlight, CSS had a few more tricks up its sleeve. Here's a look at some classic layout techniques:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inline-Block: A simple method for creating horizontal layouts. By setting elements to &lt;code&gt;display: inline-block;&lt;/code&gt;, you can line them up side by side without the need for floats.
&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="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inline-block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2%&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;ul&gt;
&lt;li&gt;Table Layouts: Yes, tables weren't just for tabular data! You could use &lt;code&gt;display: table;&lt;/code&gt;, &lt;code&gt;display: table-row;&lt;/code&gt;, and &lt;code&gt;display: table-cell;&lt;/code&gt; to create grid-like layouts.
&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="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;table-cell&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;33%&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;These methods have been largely overshadowed by modern layout techniques but still offer a glimpse into the evolution of web design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modern-Day Application: Mixing Old and New
&lt;/h2&gt;

&lt;p&gt;So, do floats and clears still have a place in the world of modern web design? Absolutely! While Flexbox and Grid are now the go-to tools for creating layouts, floats and clears can still be useful in certain scenarios, like simple layouts or when working with legacy code.&lt;/p&gt;

&lt;p&gt;For instance, you might use floats for text wrapping or when you want to align a small number of elements in a straightforward way. But for complex, responsive layouts, Flexbox and Grid are your best friends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping It Up
&lt;/h2&gt;

&lt;p&gt;Floats, clears, and other legacy layout techniques might seem like relics from the past, but they're part of the rich history of CSS. Understanding them gives you a solid foundation and helps you appreciate the power of modern layout systems. Plus, knowing these old-school tricks can come in handy when dealing with older projects or quirky design challenges (or those dreaded interview rounds).&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
Psst! If you liked what you read, you should &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;click here to checkout CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Responsive Web Design: Making Your Site Mobile-Friendly</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Fri, 16 Aug 2024 14:28:11 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/responsive-web-design-making-your-site-mobile-friendly-1elp</link>
      <guid>https://dev.to/gdebojyoti/responsive-web-design-making-your-site-mobile-friendly-1elp</guid>
      <description>&lt;p&gt;Welcome to the wonderful world of responsive web design!&lt;/p&gt;

&lt;p&gt;If you're new to web development, you might be wondering, "What makes a site &lt;em&gt;responsive&lt;/em&gt;?" Think of it like this: Responsive web design is like having a wardrobe that magically adjusts to fit every occasion - whether you're dressing for a casual brunch or a fancy gala. In web terms, it means your website looks fabulous on any device, from smartphones to tablets to desktop monitors.&lt;/p&gt;

&lt;p&gt;Ready to make your site the life of the digital party? Let's dive in!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn5j6ppauy1g7x5sqh24e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn5j6ppauy1g7x5sqh24e.png" alt="Roll Safe meme illustrating the advantage of using responsive web design to avoid layout issues across devices" width="702" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Magic of Media Queries: Your Responsive Spellbook
&lt;/h2&gt;

&lt;p&gt;Imagine you have a magical scroll that changes the appearance of your website based on the viewer's device. That's exactly what &lt;strong&gt;media queries&lt;/strong&gt; do in CSS. They let you apply different styles depending on things like screen width, orientation, and resolution. Here's how you can cast your first responsive spell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* For screens smaller than 600px */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;lightblue&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;This snippet will turn your background light blue on screens that are 600px wide or smaller. It's like giving your site a stylish makeover for mobile devices!&lt;/p&gt;

&lt;h2&gt;
  
  
  Fluid Layouts: The Stretchy Pants of Web Design
&lt;/h2&gt;

&lt;p&gt;Just as stretchy pants are perfect for &lt;em&gt;almost&lt;/em&gt; every occasion, fluid layouts allow your website to expand and contract gracefully. Instead of using fixed widths, use &lt;code&gt;%&lt;/code&gt; (percentages) or &lt;code&gt;vw&lt;/code&gt; (viewport width) units to make your layout adapt to different screen sizes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Takes up 80% of the viewport width */&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Center-aligns the container */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, your container will always take up 80% of the screen, no matter the device. Stretchy pants for your website - what's not to love?&lt;/p&gt;

&lt;h2&gt;
  
  
  Flexible Images: Making Sure Your Photos Play Nice
&lt;/h2&gt;

&lt;p&gt;Just like you wouldn't squeeze into a pair of jeans that don't fit, images on your website should resize smoothly. Use the &lt;code&gt;max-width&lt;/code&gt; property to ensure your images adjust to fit their containers without overflowing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&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;This rule ensures your images scale down if necessary but never exceed their container's width. No more broken images or awkward zooming!&lt;/p&gt;

&lt;h2&gt;
  
  
  Viewport Meta Tag: The Gateway to Mobile Bliss
&lt;/h2&gt;

&lt;p&gt;When your site is viewed on mobile devices, you need to tell the browser how to scale it properly. The viewport meta tag is your ticket to mobile-friendly magic. Add this to your HTML &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"viewport"&lt;/span&gt; &lt;span class="nt"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tag ensures your site scales correctly to fit the width of any device and keeps it looking sharp and usable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Responsive Typography: Fonts That Fit the Bill
&lt;/h2&gt;

&lt;p&gt;Just like a great outfit needs the right accessories, your website needs responsive typography to look its best. Use relative units like &lt;code&gt;em&lt;/code&gt; or &lt;code&gt;rem&lt;/code&gt; instead of fixed sizes to ensure your text scales appropriately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Scales with the user's default font size */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, your headings will look great no matter the screen size, and readers won't have to squint to read your fabulous content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing: The Ultimate Dress Rehearsal
&lt;/h2&gt;

&lt;p&gt;Before you roll out your site to the world, test it on various devices and screen sizes. Emulators and responsive design testing tools can help you see how your site looks on different screens. Think of it as a dress rehearsal before the big performance.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pro Tip&lt;/em&gt;💡&lt;br&gt;
Your favourite browser probably has dev tools that you can use to test how your site looks across different screen sizes. Use them!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Wrapping It Up
&lt;/h2&gt;

&lt;p&gt;Responsive web design is your golden ticket to creating websites that look great on any device, making sure everyone has a top-notch experience. With a bit of magic from media queries, fluid layouts, and flexible images, your site will be ready to impress on mobile, tablet, and desktop screens alike.&lt;/p&gt;

&lt;p&gt;So, get your responsive web design wand ready and start making your site mobile-friendly today. After all, in the digital age, everyone deserves a little web love, no matter what device they're using.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
Psst! If you liked what you read, you should &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;click here to checkout CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>html</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Positioning: Where Exactly Do You Think You’re Going?</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Fri, 16 Aug 2024 10:42:00 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/css-positioning-where-exactly-do-you-think-youre-going-2ec6</link>
      <guid>https://dev.to/gdebojyoti/css-positioning-where-exactly-do-you-think-youre-going-2ec6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
This article is part of a larger series that is available on my own website. &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;Click here to know more about CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcome to the magical realm of CSS positioning, where you get to play architect and designer for your web elements! If you've ever wondered how to put that button exactly where you want it, or how to make sure your header doesn't wander off, you're in the right place. Let's dive into the basics of CSS positioning with a touch of wit and a sprinkle of fun.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq3nfnscvlm9jyg0b4twq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq3nfnscvlm9jyg0b4twq.png" alt="Mocking Spongebob meme humorously suggesting to use position: absolute for all CSS layout issues" width="596" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Static Positioning: The Default Setting
&lt;/h2&gt;

&lt;p&gt;Static positioning is like the default setting on your TV. Nothing fancy, just basic and straightforward. By default, all elements are statically positioned; which means they flow in the document as you'd expect - one after another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;static&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;When you use &lt;code&gt;position: static;&lt;/code&gt;, you're essentially telling the browser to lay out the element in its normal spot, just like it would naturally. It's the "nothing to see here" of positioning.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Relative Positioning: The Slightly Shifty Friend
&lt;/h2&gt;

&lt;p&gt;Relative positioning is like having a friend who's always slightly out of place but in a charming way. It lets you move an element relative to where it would normally be, without disturbing the rest of the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.relative-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&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, &lt;code&gt;.relative-box&lt;/code&gt; will be shifted 10 pixels down and 20 pixels to the right from its &lt;em&gt;original&lt;/em&gt; position. The rest of the elements around it will still be in their original spots.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Absolute Positioning: The Freedom Seeker
&lt;/h2&gt;

&lt;p&gt;Absolute positioning is like your adventurous friend who doesn't follow the crowd. It lets you position an element anywhere you want, relative to the nearest "non-static" ancestor (i.e., an ancestor with &lt;code&gt;position: relative&lt;/code&gt;, &lt;code&gt;absolute&lt;/code&gt;, &lt;code&gt;fixed&lt;/code&gt;, or &lt;code&gt;sticky&lt;/code&gt;).&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;class=&lt;/span&gt;&lt;span class="s"&gt;"parent"&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;"child"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.child&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&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;In this example, &lt;code&gt;.child&lt;/code&gt; will be positioned 30 pixels from the top and 10 pixels from the right of the &lt;code&gt;.parent&lt;/code&gt;. If &lt;code&gt;.parent&lt;/code&gt; wasn't there, it would be positioned relative to the nearest positioned ancestor or the viewport.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pro Tip&lt;/em&gt;💡&lt;br&gt;
When an element is absolutely positioned inside a parent with &lt;code&gt;transform&lt;/code&gt; applied, it's positioned relative to the transformed parent, not the original document flow. Be mindful of this behavior to avoid unexpected layout shifts and positioning issues.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  4. Fixed Positioning: The Stubborn Static
&lt;/h2&gt;

&lt;p&gt;Fixed positioning is like having a favorite chair that you never move. It lets you position an element relative to the viewport, so it stays in the same spot no matter how much you scroll.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.floating-action-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&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;With &lt;code&gt;position: fixed;&lt;/code&gt;, the &lt;code&gt;.floating-action-button&lt;/code&gt; will stay 20 pixels from the bottom and 20 pixels from the right of the viewport, even if you scroll down. It's perfect for those sticky elements like the header of your site or a chat widget or a persistent call-to-action button.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Sticky Positioning: The Best of Both Worlds
&lt;/h2&gt;

&lt;p&gt;Sticky positioning is like having a friend who's always partially in and out of the spotlight. You can think of it as a &lt;em&gt;hybrid between relative and fixed positioning&lt;/em&gt;. An element with &lt;code&gt;position: sticky&lt;/code&gt; will stick to its position within its container when you scroll past a certain point, but otherwise behaves like a relatively positioned element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.sticky-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sticky&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;In this example, &lt;code&gt;.sticky-box&lt;/code&gt; will stick to the top of its container once you scroll past it and remain there as you continue scrolling, but only as long as the container is in view. When the container scrolls out of view, the sticky element will scroll with it. It is great for headers, navigation menus, or sidebars that you want to stay visible within a certain section of your page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Z-Index: The Overachiever
&lt;/h2&gt;

&lt;p&gt;Ah, the &lt;code&gt;z-index&lt;/code&gt;! This is where things get a bit competitive. When elements overlap, &lt;code&gt;z-index&lt;/code&gt; determines which one sits on top. It's like a high school popularity contest, but for your web elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.box2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&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;In this case, &lt;code&gt;.box1&lt;/code&gt; will appear above &lt;code&gt;.box2&lt;/code&gt; because it has a higher &lt;code&gt;z-index&lt;/code&gt;. Just remember, &lt;code&gt;z-index&lt;/code&gt; only works on positioned elements (relative, absolute, fixed, or sticky).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pro Tip&lt;/em&gt;💡&lt;br&gt;
There's more to &lt;code&gt;z-index&lt;/code&gt; than what was explained above. Stay tuned for a deeper dive into "stacking contexts", which will give you a fuller understanding of how &lt;code&gt;z-index&lt;/code&gt; works in complex layouts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Wrapping It Up
&lt;/h2&gt;

&lt;p&gt;CSS positioning might seem like a puzzle, but once you get the hang of it, you'll be placing elements with precision and flair. Each position type has its own special role in web design. Try them out and see how you can make your web page look just right.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
Psst! If you liked what you read, you should &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;click here to checkout CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Box Model: The Secret Sauce of Web Layouts</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Tue, 13 Aug 2024 20:45:26 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/css-box-model-the-secret-sauce-of-web-layouts-1c17</link>
      <guid>https://dev.to/gdebojyoti/css-box-model-the-secret-sauce-of-web-layouts-1c17</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
This article is part of a larger series that is available on my own website. &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;Click here to know more about CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcome back to the fabulous world of CSS!&lt;/p&gt;

&lt;p&gt;This time we're about to uncover one of the fundamental concepts in web design - the CSS Box Model. If you've ever wondered why elements on your page seem to have invisible padding or mysterious margins, you're in the right place.&lt;/p&gt;

&lt;p&gt;Let's dive into the boxy world of CSS and learn how this model can turn you into a layout maestro!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09vcwvwcyw9fhh5i20g5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09vcwvwcyw9fhh5i20g5.png" alt="Two Buttons meme comparing box-sizing: content-box vs box-sizing: border-box for CSS box models" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet the Box Model: Your Web Page's Underwear!
&lt;/h2&gt;

&lt;p&gt;Think of the CSS Box Model as the secret underwear of your web page. It's the foundation that keeps everything neatly tucked in and organized. Each element on your page is wrapped in a box, and this box is made up of four distinct layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Content&lt;/strong&gt;: This is the inner layer where your text, images, or any other content lives. It's like the cozy innermost layer of your box.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Padding&lt;/strong&gt;: The cushion surrounding your content. Imagine it as the soft, protective layer keeping your content from touching the edges of the box.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Border&lt;/strong&gt;: The outer frame of the box. It's the part that you can see and style with colors and thickness.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Margin&lt;/strong&gt;: The space outside the border, like the air around your box. It creates space between your element and others around it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Content: The Star of the Show
&lt;/h2&gt;

&lt;p&gt;Content is where all the magic happens. It's where you place your text, images, and other elements. You control the size of the content area using properties like &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&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;This defines the size of your content area. Since the content area is where your stuff goes, do make sure it's spacious enough for everything you want to fit in!&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Padding: The Cozy Blanket
&lt;/h2&gt;

&lt;p&gt;Padding is like the comfy blanket you throw over your content. It's the space between the content and the border, making sure your content isn't snuggling too close to the edges.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&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;This adds a 20px cushion around your content. It's like giving your content a little breathing room.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Border: The Stylish Frame
&lt;/h2&gt;

&lt;p&gt;Border is the stylish frame that surrounds your content and padding. You can customize its color, width, and style. It's like choosing the perfect picture frame for your artwork.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#007BFF&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, you've got a 2px solid blue border around your box. Feel free to get creative with dashed, dotted, or even double borders!&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Margin: The Elusive Space
&lt;/h2&gt;

&lt;p&gt;Margins are the space outside the border. They're like the invisible force field that keeps elements apart. Use margins to control the distance between your box and other elements on the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&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;This adds a 30px space around your box, ensuring it doesn't bump into its neighbours. It's like giving your box some personal space!&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Box Sizing: Adjusting the Box's Behavior
&lt;/h2&gt;

&lt;p&gt;By default, the box model adds padding and border to the element's width and height, making the actual size larger than what you specify. If you want to change this behavior, use the box-sizing property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&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;With &lt;code&gt;border-box&lt;/code&gt;, the width and height you set include the padding and border. It's like giving your box a makeover so it fits exactly how you want it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pro Tip&lt;/em&gt;💡&lt;br&gt;
The default &lt;code&gt;box-sizing&lt;/code&gt; value is &lt;code&gt;content-box&lt;/code&gt;, which excludes padding and borders from width and height calculations. Switching to &lt;code&gt;box-sizing: border-box&lt;/code&gt; can simplify layout management by including padding and borders in the element's total size.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Wrapping It Up
&lt;/h2&gt;

&lt;p&gt;The CSS Box Model might seem like a lot to take in; but once you get the hang of it, you'll find it's the key to mastering layouts and spacing on your web page. Remember, every element on your page is a box with content, padding, border, and margin. Get comfortable with these concepts, and you'll be styling like a pro in no time.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
Psst! If you liked what you read, you should &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;click here to checkout CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS Selectors: Your New Best Friends for Styling Web Pages</title>
      <dc:creator>Debojyoti Ghosh</dc:creator>
      <pubDate>Tue, 13 Aug 2024 15:36:41 +0000</pubDate>
      <link>https://dev.to/gdebojyoti/css-selectors-your-new-best-friends-for-styling-web-pages-4f9p</link>
      <guid>https://dev.to/gdebojyoti/css-selectors-your-new-best-friends-for-styling-web-pages-4f9p</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
This article is part of a larger series that is available on my own website. &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;Click here to know more about CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcome to the fabulous world of CSS!&lt;/p&gt;

&lt;p&gt;If you're new to web development, you might be wondering, "What on earth are CSS selectors, and why should I care?" Well, CSS selectors are like your trusty magic wand in the realm of web development. They let you pick out specific elements on your webpage and give them a stylish makeover.&lt;/p&gt;

&lt;p&gt;Let's dive into the basics and learn how to make your website look fabulous!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapw7diy2r0kbj9f6musl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapw7diy2r0kbj9f6musl.png" alt="CSS selectors meme: With the great power of CSS selectors, comes great responsibility" width="800" height="597"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Universal Selector: The Ultimate Catch-All
&lt;/h2&gt;

&lt;p&gt;Imagine you're a wizard casting a spell over everything in sight. That’s what the universal selector &lt;code&gt;*&lt;/code&gt; does. It targets every single element on your web page. Use it wisely, as it can be a bit overzealous if you’re not careful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;This little snippet will strip away all margins and paddings from every element. It's like hitting the reset button on your webpage!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pro Tip&lt;/em&gt;💡&lt;br&gt;
A &lt;strong&gt;CSS reset&lt;/strong&gt; removes default browser styles from HTML elements to ensure a consistent look across different browsers. It provides a clean starting point for designing and styling web pages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2. The Class Selector: Your Personal Stylist
&lt;/h2&gt;

&lt;p&gt;When you need to give specific elements a makeover without affecting everything else, the class selector is your go-to option. Think of it like picking out an outfit for a special occasion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#007BFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&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;Now any element with the &lt;code&gt;button&lt;/code&gt; class will get a snazzy blue background and white text. Perfect for making those call-to-action buttons pop!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pro Tip&lt;/em&gt;💡&lt;br&gt;
Restricting your CSS to &lt;strong&gt;class selectors&lt;/strong&gt; helps maintain consistent styling and simplifies overrides by keeping specificity low. This approach enhances readability and makes your CSS easier to manage, especially in larger projects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. The ID Selector: The VIP Pass
&lt;/h2&gt;

&lt;p&gt;The ID selector is for elements that are so unique that they deserve their very own style. It's like giving a VIP pass to an exclusive club.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nf"&gt;#header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&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, &lt;code&gt;#header&lt;/code&gt; targets just one element with that ID. Remember, IDs should be unique on a page, so don’t try to give the same ID to multiple elements unless you want a styling catastrophe!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Pro Tip&lt;/em&gt;💡&lt;br&gt;
Make sure each ID on your web page is unique. This helps prevent potential issues with JavaScript and ensures your scripts work correctly by targeting the right elements.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  4. The Descendant Selector: The Family Reunion
&lt;/h2&gt;

&lt;p&gt;Sometimes you want to style elements that are nested inside others. That's where the descendant selector comes in. It's like giving a family reunion a new look.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;nav&lt;/span&gt; &lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#007BFF&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;This targets all &lt;code&gt;a&lt;/code&gt; (anchor) tags inside &lt;code&gt;li&lt;/code&gt; elements, which are themselves inside a &lt;code&gt;nav&lt;/code&gt; element. It's a way to ensure your navigation links look perfect without disturbing other links on the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The Pseudo-Class Selector: The Style Chameleon
&lt;/h2&gt;

&lt;p&gt;For those times when you want to style an element based on its state (like when a user hovers over it), the pseudo-class selector is what you want. It changes its style based on the situation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#FF5722&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 above makes links turn a vibrant orange when you hover over them. It adds a little interactive flair to your page.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. The Attribute Selector: The Selective Sleuth
&lt;/h2&gt;

&lt;p&gt;Sometimes you want to style elements based on their attributes. The attribute selector helps you pinpoint exactly what you need, like a detective finding a clue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;input&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;"text"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#007BFF&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;This targets only text input fields and gives them a blue border. Handy for ensuring users know where to type!&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping It Up
&lt;/h2&gt;

&lt;p&gt;CSS selectors might seem cryptic at first - but with a little practice, you'll be styling your web pages like a pro. They are the fundamental building blocks in your toolkit for making your site look just the way you want. So, go forth and get styling.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✨&lt;br&gt;
Psst! If you liked what you read, you should &lt;a href="https://debojyotighosh.com/blog/css-101-the-series/" rel="noopener noreferrer"&gt;click here to checkout CSS 101: The Series&lt;/a&gt;. It's completely free!&lt;/p&gt;
&lt;/blockquote&gt;

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