<?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: Jeje ✨ (Джиджи) </title>
    <description>The latest articles on DEV Community by Jeje ✨ (Джиджи)  (@crispy-broccoli).</description>
    <link>https://dev.to/crispy-broccoli</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%2F889360%2F238500dd-4305-4f77-8984-cd047c4ad37f.jpeg</url>
      <title>DEV Community: Jeje ✨ (Джиджи) </title>
      <link>https://dev.to/crispy-broccoli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/crispy-broccoli"/>
    <language>en</language>
    <item>
      <title>What is Ternary Operator in JavaScript?</title>
      <dc:creator>Jeje ✨ (Джиджи) </dc:creator>
      <pubDate>Sat, 14 Jun 2025 06:30:23 +0000</pubDate>
      <link>https://dev.to/crispy-broccoli/what-is-ternary-operator-in-javascript-1835</link>
      <guid>https://dev.to/crispy-broccoli/what-is-ternary-operator-in-javascript-1835</guid>
      <description>&lt;p&gt;If you're learning JavaScript and came across something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let message = age &amp;gt; 18 ? "Welcome!" : "Sorry, you're too young.";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...and thought, "What is that question mark doing in the middle of the code?"&lt;br&gt;
You're not alone!&lt;/p&gt;

&lt;p&gt;That is called a &lt;strong&gt;ternary operator&lt;/strong&gt;.It might look strange at first, but it's actually a simple and powerful way to write decisions in code.&lt;/p&gt;

&lt;p&gt;Let's break it down step by step.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is the Ternary Operator?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;ternary operator&lt;/strong&gt; is a conditional operator that evaluates a condition and returns one of two values depending on whether the condition is true or false.&lt;/p&gt;

&lt;p&gt;It has this structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;condition ? expressionIfTrue : expressionIfFalse;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In other words, the &lt;strong&gt;ternary operator&lt;/strong&gt; is a shortcut for writing a simple &lt;strong&gt;if-else&lt;/strong&gt; statements in one line.&lt;br&gt;
It's called &lt;em&gt;ternary&lt;/em&gt; because it uses three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A condition (something that is either true or false)&lt;/li&gt;
&lt;li&gt;A result if the condition is true&lt;/li&gt;
&lt;li&gt;A result if the condition is false&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Let's say you're writing a program to check someone's age:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age = 20;
let message = age &amp;gt;= 18 ? "You can vote." : "You are too young to vote.";
console.log(message); // Output: "You can vote."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what this code does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It checks: is age 18 or more?&lt;/li&gt;
&lt;li&gt;If yes, it gives the message: "You can vote."&lt;/li&gt;
&lt;li&gt;If no, it gives: "You're too young to vote."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's the same as writing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let message;
if (age &amp;gt;= 18) {
  message = "You can vote.";
} else {
  message = "You're too young to vote.";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But shorter and cleaner!&lt;/p&gt;

&lt;h2&gt;
  
  
  When is it a good idea?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Ternary Operator&lt;/strong&gt; is not meant to replace &lt;strong&gt;if-else&lt;/strong&gt; statement. Use it when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to choose between two values&lt;/li&gt;
&lt;li&gt;You are assigning a value (like a message or label)&lt;/li&gt;
&lt;li&gt;The decision is simple (easy to understand)&lt;/li&gt;
&lt;li&gt;You want to write it all in one line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let isMember = true;
let price = isMember ? "$20" : "$35";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When should you avoid it?
&lt;/h2&gt;

&lt;p&gt;Sometimes using the ternary operator can make your code harder to read, especially when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The condition is too long or complex&lt;/li&gt;
&lt;li&gt;You're stacking multiple ternaries on top of each other&lt;/li&gt;
&lt;li&gt;You're not just returning values, but doing actions (like showing messages, logging in, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of what &lt;strong&gt;NOT&lt;/strong&gt; to do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = score &amp;gt; 90 ? "A" : score &amp;gt; 80 ? "B" : score &amp;gt; 70 ? "C" : "F";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, it's better to use regular &lt;strong&gt;if-else&lt;/strong&gt; blocks for things like this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Verdict
&lt;/h2&gt;

&lt;p&gt;The ternary operator is like a mini decision-making machine in JavaScript. Once you get the hang of it, you'll find it super useful for simple &lt;em&gt;yes or no&lt;/em&gt; style logic.&lt;/p&gt;

&lt;p&gt;Just remember these best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use ternary for simple value decisions&lt;/li&gt;
&lt;li&gt;keep it short and readable&lt;/li&gt;
&lt;li&gt;Don't let it become a puzzle others have to solve&lt;/li&gt;
&lt;li&gt;Don't use it to replace full blocks of logic
** Avoid nested ternaries unless absolutely necessary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you can read it easily a day later, you're probably using it right. 😊&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Understanding Type Coercion in JavaScript</title>
      <dc:creator>Jeje ✨ (Джиджи) </dc:creator>
      <pubDate>Mon, 09 Jun 2025 05:49:19 +0000</pubDate>
      <link>https://dev.to/crispy-broccoli/understanding-type-coercion-in-javascript-35k5</link>
      <guid>https://dev.to/crispy-broccoli/understanding-type-coercion-in-javascript-35k5</guid>
      <description>&lt;p&gt;In JavaScript, &lt;strong&gt;type coercion&lt;/strong&gt; is the automatic or implicit conversion of one data type to another. It happens when JavaScript tries to &lt;em&gt;make sense of different types being used together&lt;/em&gt;, or like  when a number is added to a string, or when values are compared using loose equality (==).&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("5" + 1); // "51"
console.log("5" - 1); // 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you notice the first one becomes a &lt;strong&gt;string&lt;/strong&gt; and the second one becomes a &lt;strong&gt;number&lt;/strong&gt;?&lt;br&gt;
This is type coercion. JavaScript tries to be &lt;em&gt;helpful&lt;/em&gt; by guessing what you want. Sometimes it gets it right, other times it causes bugs if you're not careful.&lt;/p&gt;
&lt;h2&gt;
  
  
  Two types of coercion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Implicit Coercion&lt;/strong&gt;&lt;br&gt;
JavaScript automatically converts the type for you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"2" * 3    // 6 → string "2" is turned into number
true + 1   // 2 → true becomes 1

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explicit Coercion&lt;/strong&gt;&lt;br&gt;
You manually convert the type using functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Number("5");   // 5
String(123);   // "123"
Boolean(0);    // false

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

&lt;/div&gt;



&lt;p&gt;JavaScript uses internal rules called &lt;em&gt;Abstract Operations&lt;/em&gt; in the spec to coerce values based on the operator or context. This happens because JavaScript tries to make a comparison or calculation work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of value coercion
&lt;/h2&gt;

&lt;p&gt;Let's look at how coercion works for each value type: &lt;strong&gt;string&lt;/strong&gt;, &lt;strong&gt;number&lt;/strong&gt;, and &lt;strong&gt;boolean&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  String coercion
&lt;/h3&gt;

&lt;p&gt;When JavaScript sees a + operator with one operand being a string, it converts the other operand to a string, and then concatenates. The + operator is the only arithmetic operator that triggers string coercion if either operand is a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Hello" + 42    // "Hello 42"
true + " days"  // "true days"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Number coercion
&lt;/h3&gt;

&lt;p&gt;Occurs in math operations like -,/, or with comparisons like &amp;lt;,&amp;gt;, and sometimes in loose equality (==). In this case, operands are converted to numbers &lt;strong&gt;unless + is involved with strings&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"10" - 3       // 7 → string becomes number
true * 2       // 2 → true becomes 1
null + 1       // 1 → null becomes 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Boolean coercion
&lt;/h3&gt;

&lt;p&gt;Used in logical expressions (if, while, for, etc).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Boolean("")     // false
Boolean("0")    // true
Boolean([])     // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;These values are &lt;strong&gt;falsy&lt;/strong&gt; in JavaScript:
false, 0, "", null, undefined, NaN&lt;/li&gt;
&lt;li&gt;Everything else is &lt;strong&gt;truthy&lt;/strong&gt; (even [], {}, "false", "0")&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Loose equality (==) and coercion rules
&lt;/h3&gt;

&lt;p&gt;The == operator allows type coercion during comparison.&lt;br&gt;
Examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 == "1"       // true
false == 0     // true
null == undefined  // true
[] == false    // true 😬
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But be careful! These comparisons can be confusing, especially with arrays and objects.&lt;br&gt;
Instead, use === (strict equality) which doesn't do coercion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 === "1"      // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why type coercion matters?
&lt;/h2&gt;

&lt;p&gt;For one, it can be very useful for flexibility, but it can also become unpredictable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Less code to write&lt;/li&gt;
&lt;li&gt;Can be useful in simple logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can lead to bugs or weird behaviour&lt;/li&gt;
&lt;li&gt;Harder to debug for beginners&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding when coercion happens helps you write cleaner code and avoid mistakes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best practices to avoid bugs
&lt;/h2&gt;

&lt;p&gt;Here are some tips to stay safe when dealing with type coercion:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Use === instead of ==
&lt;/h3&gt;

&lt;p&gt;Always prefer strict equality to avoid surprise conversions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (value === 0) { ... } // safer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Convert values explicitly
&lt;/h3&gt;

&lt;p&gt;Don't rely on JavaScript to guess your intent.&lt;br&gt;
Use &lt;code&gt;Number()&lt;/code&gt;, &lt;code&gt;String()&lt;/code&gt;, &lt;code&gt;Boolean()&lt;/code&gt;instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const input = "5";
const num = Number(input); // good
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Watch out for falsy values
&lt;/h3&gt;

&lt;p&gt;Be mindful that "", 0, null, and undefined all count as false in conditionals.&lt;br&gt;
Use &lt;code&gt;=== null&lt;/code&gt; or &lt;code&gt;=== undefined] when needed.&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;br&gt;
if (value) { ... } // may skip valid values like 0&lt;br&gt;
&lt;/code&gt;`&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Don't compare complex types (Like arrays or objects)
&lt;/h3&gt;

&lt;p&gt;Even if they look the same, objects are compared by &lt;strong&gt;reference&lt;/strong&gt;, not value.&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
{} == {}     // false&lt;br&gt;
[] == []     // false&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Type coercion is one of those things that can make or break your JavaScript skills. It's okay to feel confused at first.&lt;/p&gt;

&lt;p&gt;Just remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Know when JavaScript values&lt;/li&gt;
&lt;li&gt;Use === and explicit conversions to avoid surprises&lt;/li&gt;
&lt;li&gt;Test edge cases like empty strings, null, and undefined&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Iterate Over a Plain Object in Javascript</title>
      <dc:creator>Jeje ✨ (Джиджи) </dc:creator>
      <pubDate>Fri, 02 Sep 2022 10:08:51 +0000</pubDate>
      <link>https://dev.to/crispy-broccoli/how-to-iterate-over-a-plain-object-in-javascript-5743</link>
      <guid>https://dev.to/crispy-broccoli/how-to-iterate-over-a-plain-object-in-javascript-5743</guid>
      <description>&lt;p&gt;Before continue on reading and follow the tutorials, ensure you satisfy the following prerequisite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Working knowledge of Javascript data structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Though not common, but sometimes you might find yourself in situations where you need to loop through a Javascript object. Unlike &lt;em&gt;strings&lt;/em&gt; and &lt;em&gt;arrays&lt;/em&gt;, objects, literal objects with curly brackets and &lt;em&gt;key: value pair&lt;/em&gt; are not considered to be iterable.&lt;/p&gt;

&lt;p&gt;So, if you go with the &lt;code&gt;for... of&lt;/code&gt; method to iterate the following objects like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;fruitsQty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;melon:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="nl"&gt;apple:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="nl"&gt;grape:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="nl"&gt;pineapple:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="nl"&gt;jackfruit:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="nl"&gt;strawberry:&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="nl"&gt;orange:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="n"&gt;exm&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;fruitsQty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exm&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;You'll get an error.&lt;/p&gt;

&lt;p&gt;However, if you present that object key:value pairs as an array, you'll be able to use the &lt;code&gt;for...of&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;In order to do that, you need to use special methods: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Object.keys()&lt;/code&gt; to return an actual array containing the keys out of the object as an array&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Object.values()&lt;/code&gt; to return an actual array made up of the values out of that object&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Object.entries()&lt;/code&gt; which will return a literal nested arrays of the key:value pair of that object.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruitsQty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// (7) ["melon", "apple", "grape", "pineapple", "jackfruit", "strawberry", "orange"]&lt;/span&gt;

&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruitsQty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// (7) [10, 15, 7, 10, 22, 14, 30]&lt;/span&gt;

&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruitsQty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ["melon" 10, "apple" 15, "grape" 7, "pineapple" 10, "jackfruit" 22, "strawberry" 14, "orange" 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have those presented as an array (technically they are not turned into an array, we just sort of make array out of an object, ok apologies if this is confusing lol), we can use the previous &lt;code&gt;for...of&lt;/code&gt; method to iterate that object because that does work with an array.&lt;/p&gt;

&lt;p&gt;Here's an example of iterating over the quantity of the fruit&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="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;quantity&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruitsQty&lt;/span&gt;&lt;span class="p"&gt;)&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="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="mi"&gt;22&lt;/span&gt;
&lt;span class="mi"&gt;14&lt;/span&gt;
&lt;span class="mi"&gt;30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, using those three methods will allow you iterate over objects using the &lt;code&gt;for..of&lt;/code&gt; method as if they are an array. You can also loop through them to get the total quantity of the fruits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="n"&gt;sum&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="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fruitsQty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Each time it loops, the sum adds each fruit quantity&lt;/span&gt;
&lt;span class="c1"&gt;// 108&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since those keys and values are behaving like an array with those methods, you can also find out the length of the fruits quantity, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// first, create a variable that stores the fruit quantity information as an array&lt;/span&gt;

&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fruitsQty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Photography Portfolio with CSS Only</title>
      <dc:creator>Jeje ✨ (Джиджи) </dc:creator>
      <pubDate>Wed, 03 Aug 2022 17:12:00 +0000</pubDate>
      <link>https://dev.to/crispy-broccoli/photography-showcase-with-css-only-5b25</link>
      <guid>https://dev.to/crispy-broccoli/photography-showcase-with-css-only-5b25</guid>
      <description>&lt;p&gt;You can create a beautiful photography portfolio website with just a HTML and CSS. And yes, you can achieve that zoom photos effect without javascript. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Important CSS to apply&lt;/strong&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="nt"&gt;img&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;border-radius&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;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;calc&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="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="m"&gt;0.5s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;transition&lt;/code&gt; property makes sure when the zoom takes effect, it'll happen smoothly.&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="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f9fbe7&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="m"&gt;13px&lt;/span&gt; &lt;span class="m"&gt;27px&lt;/span&gt; &lt;span class="m"&gt;-5px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#fff59d&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="m"&gt;-8px&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="n"&gt;calc&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="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&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;9999&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.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;Now, Using the &lt;code&gt;transform&lt;/code&gt; property, I define the &lt;code&gt;scale()&lt;/code&gt; method, where the image width will increase on hover by 1.5 but of course it can be bigger than that, depends on your liking. The &lt;code&gt;z-index&lt;/code&gt; is there so as to ensure when zoomed in, it will always be stacked on top of everything else.&lt;/p&gt;

&lt;p&gt;Lastly, here's where it gets interesting. I want to make sure all images on the most left and right side of the screen to NOT overflow when they are zoomed in. To do this, I need to make sure the images on the most left and right move slightly to the center of the screen when on hover. So, there are two problems I need to solve:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How to move the images on the most right side to the left and images on the most left to the right?&lt;/li&gt;
&lt;li&gt;How do I make CSS choose only those images positioned on the most left and right side of the screen?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I achieve the first objective by using the &lt;code&gt;transform: translateX();&lt;/code&gt; method applied on the &lt;code&gt;img:hover&lt;/code&gt;. So images will move horizontally along the X axis.&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 images on the most left, use a positive value */&lt;/span&gt;
&lt;span class="nt"&gt;transform&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;translateX&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;40&lt;/span&gt;&lt;span class="o"&gt;%);&lt;/span&gt;

&lt;span class="c"&gt;/* for images on the most right, use a negative value as it moves to the opposite direction */&lt;/span&gt;
&lt;span class="nt"&gt;transform&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;translateX&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;-40&lt;/span&gt;&lt;span class="o"&gt;%);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the second question can be answered using the &lt;code&gt;nth:child()&lt;/code&gt; property. Basically, to select every pic on the most left of the screen, I need to select the 1st, 4th, and 7th children. In other words, increase the number by 3.&lt;/p&gt;

&lt;p&gt;To achieve that, I use &lt;code&gt;img:nth-child(3n+1):hover&lt;/code&gt; as this ensures the style will ONLY be applied to the first child and every subsequent 3rd child of the siblings. Meanwhile, to select every pic on the most right of the screen, I use the following formula: &lt;code&gt;img:nth-child(3n+3):hover&lt;/code&gt;. Because it starts from the 3rd child and also selects every subsequent 3rd child after it.&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;/* ensures all images on the most left moves slightly to the right so the pictures won't overflowed when zoomed in*/&lt;/span&gt;
&lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="nt"&gt;n&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&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;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;40%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* ensures all images on the most right moves slightly to the left so the pictures won't overflowed when zoomed in*/&lt;/span&gt;
&lt;span class="nt"&gt;img&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="nt"&gt;n&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="err"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&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;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-40%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.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;



</description>
      <category>html</category>
      <category>css</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Stop Using IDs and Classes in Every HTML Element!</title>
      <dc:creator>Jeje ✨ (Джиджи) </dc:creator>
      <pubDate>Sun, 24 Jul 2022 17:15:00 +0000</pubDate>
      <link>https://dev.to/crispy-broccoli/stop-using-ids-and-classes-in-every-html-element-3k2c</link>
      <guid>https://dev.to/crispy-broccoli/stop-using-ids-and-classes-in-every-html-element-3k2c</guid>
      <description>&lt;p&gt;Ola! So, this is something I've just come to a realisation recently and if you're a newbie in the world of web development then it's easy for you to forget all the variations of CSS attribute selectors and just opt for creating a specific class or ID to style a particular element in your page.&lt;/p&gt;

&lt;p&gt;Case in point? Suppose you have a flex container containing 10 flex items that looks like this:&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-column"&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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 4&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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 5&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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 6&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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 7&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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 8&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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 9&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;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 10&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;You want the first flex item to have a different &lt;code&gt;background-color&lt;/code&gt;. You're probably thinking of creating an ID for this since this style is only unique for this item, right? &lt;/p&gt;

&lt;p&gt;Well, what if we have the same flex container with 10 flex items in every page on our website? and we want the first item to have the same style? &lt;em&gt;well just add another class to it, duh!&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Technically, that can be done but this is not the best practice! We should make use of the CSS attribute selectors, more specifically the &lt;code&gt;:pseudo-classes&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;CSS &lt;code&gt;:pseudo-classes&lt;/code&gt; helps you single out an HTML element by its particular state, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:hover&lt;/code&gt; When you hover a cursor over a button&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:active&lt;/code&gt; When a link or a button is being clicked&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:checked&lt;/code&gt; When radio buttons are checked&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:first-child&lt;/code&gt; and &lt;code&gt;:last-child&lt;/code&gt; Apply the style to the first and last element that appears immediately and lastly under its parent element, respectively&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:nth-child&lt;/code&gt; Applies the style to a children element with a particular position in a group of sibling elements, e.g., the third 'p' in every &lt;code&gt;div&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the dummy HTML code above, we can make up a few scenarios with a &lt;code&gt;background-color&lt;/code&gt; use case:&lt;/p&gt;

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

&lt;p&gt;Let's start from top to bottom there. There are two displays: a column and a row.&lt;/p&gt;

&lt;h3&gt;
  
  
  Column
&lt;/h3&gt;

&lt;p&gt;I want the boxes in odd positions (boxes number 1, 3, 5, 7, and 9) to be in an orange-ish color so I target them using the following :pseudo-class, specifying in the bracket that I want to target ODD numbers.&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;.item&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;odd&lt;/span&gt;&lt;span class="o"&gt;)&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;#FEC8A7&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;Same thing with the boxes with even number positions, I just replaced the word &lt;em&gt;odd&lt;/em&gt; inside the bracket with &lt;code&gt;(even)&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;.item&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;even&lt;/span&gt;&lt;span class="o"&gt;)&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;#FCECA5&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;h3&gt;
  
  
  Row
&lt;/h3&gt;

&lt;p&gt;On my Row display, I wanted to target only the first and last boxes. So this is where the &lt;code&gt;:first-child&lt;/code&gt; and &lt;code&gt;last-child&lt;/code&gt; come into play:&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;/* targets the first flex item */&lt;/span&gt;
&lt;span class="nc"&gt;.item2&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;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#A16AE8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* targets the last flex item */&lt;/span&gt;
&lt;span class="nc"&gt;.item2&lt;/span&gt;&lt;span class="nd"&gt;:last-child&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;#4120A9&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;Fun fact, alternatively you can replace the &lt;code&gt;:first-child&lt;/code&gt; with &lt;code&gt;:first-of-type&lt;/code&gt; or &lt;code&gt;:nth-child(1)&lt;/code&gt;, along with &lt;code&gt;:last-child&lt;/code&gt; being replaceable with &lt;code&gt;:last-of-type&lt;/code&gt; in this use case and they'd still deliver the same result! The difference is that, &lt;code&gt;:first-of-type&lt;/code&gt; will seek ONLY the first occurrence of the said element in the container/parent element, even if it's not the first child of the container/parent element. So, if I slightly change the code for the Row display above by adding an &lt;code&gt;h1&lt;/code&gt; like this:&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-row"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;header&lt;span class="nt"&gt;&amp;lt;/h1&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 4&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 5&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 6&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 7&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 8&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 9&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 10&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 10&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;"item2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;flex item 10&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;Using &lt;code&gt;:first-child&lt;/code&gt; or &lt;code&gt;:nth-child(1)&lt;/code&gt; will not work! Because the first child of the container is the &lt;code&gt;h1&lt;/code&gt;. But it will still work with &lt;code&gt;:first-of-type&lt;/code&gt;, because it will look for the first occurrence &lt;code&gt;.item2&lt;/code&gt; class in the container. In other words, &lt;code&gt;:first-child&lt;/code&gt; and &lt;code&gt;:nth-child&lt;/code&gt; are more specific in this case and are recommended to be used in practice if you want to target a really specific element position.&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>html</category>
    </item>
    <item>
      <title>Zoom Images on Mouse Hover Using CSS Only</title>
      <dc:creator>Jeje ✨ (Джиджи) </dc:creator>
      <pubDate>Wed, 13 Jul 2022 10:10:07 +0000</pubDate>
      <link>https://dev.to/crispy-broccoli/zoom-images-on-mouse-hover-using-css-only-1e9k</link>
      <guid>https://dev.to/crispy-broccoli/zoom-images-on-mouse-hover-using-css-only-1e9k</guid>
      <description>&lt;p&gt;I love it when I visit a site and every time I click on an image, it enlarges automatically. It's one of the essential web designs to make websites more alive. It's especially important if there are crucial information in that image that you want the readers to read, so they can easily zoom in on the texts. I've googled tricks to do it and most, if not all, involve a little bit of javascript in action.&lt;/p&gt;

&lt;p&gt;I'll show you that it's possible to make an interactive image using CSS only. So, if you're just starting out your web development journey and you have yet to dip your foot into the Javascript pool, you can definitely follow my method with ease.&lt;/p&gt;

&lt;p&gt;Here's an example, go hover on the image :D.&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/koselige/embed/PoRGaXN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That thing can be achieved by just a few lines in your CSS file. &lt;br&gt;
Let's dissect the code one by one&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The HTML&lt;/strong&gt;&lt;br&gt;
I wrap the image in a flex container, just because it's flexbox and flexbox makes life easy. Everyone says thank you Flexbox! :)&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;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"Family-Guy"&lt;/span&gt; 
&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://static.stacker.com/s3fs-public/styles/sar_screen_maximum_large/s3/2019-08/Untitled%20design%20-%202019-08-23T235151.866.webp"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Family Guy"&lt;/span&gt;&lt;span class="nt"&gt;&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;&lt;strong&gt;The CSS&lt;/strong&gt;&lt;br&gt;
Now, we want the zoom to take effect when we hover our cursor on the image. So, make sure you define the &lt;code&gt;:hover pseudo class&lt;/code&gt; on the &lt;code&gt;img&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;And here's where it gets interesting, add &lt;code&gt;animation&lt;/code&gt; attribute to your &lt;code&gt;:hover pseudo class&lt;/code&gt;. Yep! The &lt;code&gt;CSS animation&lt;/code&gt; takes css to the next level as it lets you animate literal static properties and transition them from one CSS style to another, gradually and smoothly.&lt;/p&gt;

&lt;p&gt;Here's what you need to do first with 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="nt"&gt;body&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;.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;justify-content&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="nl"&gt;margin&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="nf"&gt;#Family-Guy&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;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&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;300px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#Family-Guy&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;animation-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;on-hover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;animation-duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;animation-fill-mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;forwards&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;on-hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%&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="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&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;600px&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;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;First, define the animation-name as it will later be called by the &lt;code&gt;keyframes&lt;/code&gt;. Then, define how long the zoom in will take effect in seconds. &lt;/p&gt;

&lt;p&gt;Lastly, specify how you want the animation style to apply. The &lt;code&gt;animation-fill-mode&lt;/code&gt; property determines what happens &lt;em&gt;before&lt;/em&gt; the animation begins and &lt;em&gt;after&lt;/em&gt; the animation ends. If you leave this out, the value is set to none by default.&lt;/p&gt;

&lt;p&gt;Of course, we use &lt;code&gt;forwards&lt;/code&gt; for this case. Because we want the image to stay zoomed in UNTIL the cursor no longer hovers on it. With &lt;code&gt;forwards&lt;/code&gt;, the last animation style (defined in the &lt;code&gt;keyframes&lt;/code&gt; property) will be retained afterwards. Here are other possible values for the &lt;code&gt;animation-fill-mode&lt;/code&gt; property:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;none&lt;/code&gt; This is the default value and no animation style will be applied.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;backwards&lt;/code&gt; The animation will go back to its initial style set in the keyframe after the whole styles have been applied. So, if we apply this value in the CSS above, the image will go back to its initial width after being zoomed, even when the cursor is still hovering on it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;both&lt;/code&gt; This will apply the animation styles before and after the animation starts.&lt;/p&gt;

&lt;p&gt;The real magic actually happens because of the &lt;code&gt;keyframes&lt;/code&gt; property here. This is where we define what CSS styles will be applied, how and when the styles should transition.&lt;/p&gt;

&lt;p&gt;The code to specify can be in percent, as used above or with keywords &lt;code&gt;from&lt;/code&gt; and &lt;code&gt;to&lt;/code&gt;, which is similar to percent. Using percent is recommended for the best browser compatibility though!&lt;/p&gt;

&lt;p&gt;In the example above, the 0% represents the initial state of the image, where nothing happens except I decrease the opacity. Nothing fancy...&lt;/p&gt;

&lt;p&gt;Then, at 100%, I define the width to be 600px, which is twice the size of the initial image size. There's no limit on how many keyframes property you use in one animation. But this is a simple example in the hopes you can understand it easily.&lt;/p&gt;

&lt;p&gt;So, there you go folk! Simple but powerful enough to make your website slightly interactive. Hope this helps. Ciao kakao!&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>[Sphinx] Inserting Media in Restructured Text (ReST) Files</title>
      <dc:creator>Jeje ✨ (Джиджи) </dc:creator>
      <pubDate>Wed, 13 Jul 2022 07:34:40 +0000</pubDate>
      <link>https://dev.to/crispy-broccoli/sphinx-inserting-media-in-restructured-rest-files-2amn</link>
      <guid>https://dev.to/crispy-broccoli/sphinx-inserting-media-in-restructured-rest-files-2amn</guid>
      <description>&lt;p&gt;If you are building documentation using Sphinx (python static site generator), you'll have to learn a plain markup language called ReStructured Text (ReST). ReST has a pretty unique syntax all around, so if you're wondering how many ways we can insert media in this file, keep on reading!&lt;/p&gt;

&lt;p&gt;So, in order to follow this tutorial you must at least have a basic understanding of the reST syntax. Knowing what a &lt;a href="https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html" rel="noopener noreferrer"&gt;directive&lt;/a&gt; is is enough to get you started. &lt;/p&gt;

&lt;p&gt;To insert media such as images or gifs, use directives like so:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.. image::&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;.. figure::&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;.. thumbnail::&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;● If you want to insert an image or GIF with a caption, use the figure directive.&lt;br&gt;
● If you want to insert an image or GIF that can be enlarged when you click on it (also known as Lightbox), use the thumbnail directive. In practice, it’s better to always use this directive for images&lt;br&gt;
● Use image directive to insert small icons or buttons. Since this directive can be used for &lt;em&gt;substitution definition&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Thumbnail
&lt;/h2&gt;

&lt;p&gt;Personally, you should use Thumbnail in most of your images as this is the most customisable directive for media. Unfortunately, this is not a built-in feature in Sphinx so it comes as an extension. To use this directive, you must install it first and then configure your &lt;strong&gt;conf.py&lt;/strong&gt; file by adding the lightbox extension.&lt;/p&gt;
&lt;h3&gt;
  
  
  Installing Lightbox
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run the following command &lt;code&gt;pip install sphinxcontrib-images&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;After the package has been successfully installed, open your &lt;strong&gt;conf.py&lt;/strong&gt; file and add the following extension:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt; &lt;span class="n"&gt;extensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="err"&gt;…&lt;/span&gt;
          &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;sphinxcontrib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="err"&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;Additionally, you can further customise image behavior, i.e., width, height, download or title in the &lt;strong&gt;conf.py&lt;/strong&gt; by adding this parameter:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt; &lt;span class="n"&gt;images_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;…&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt; &lt;span class="c1"&gt;#lightbox behavior
&lt;/span&gt; &lt;span class="n"&gt;images_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;backend&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;LightBox2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;default_image_width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;100%&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;default_show_title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;True&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;default_group&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default&lt;/span&gt;&lt;span class="sh"&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;ul&gt;
&lt;li&gt;Now, you can start using the

&lt;code&gt;.. thumbnail::&lt;/code&gt;

directive in your ReST file. Here's an example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt; &lt;span class="p"&gt;..&lt;/span&gt; &lt;span class="n"&gt;thumbnail&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;center&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;title&lt;/em&gt; attribute here is a caption that appears when the lightbox takes effect, that is when you zoom in on the image. You can use the similar wording for both the title and alt texts.&lt;/p&gt;

&lt;p&gt;Other attributes you can use for the Thumbnail directive are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:download: True&lt;/code&gt; This lets you to download remote images.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:width:&lt;/code&gt; and &lt;code&gt;:height:&lt;/code&gt; These are pretty self-explanatory. If you define this as in your image attribute, it will override the default backend configuration you defined in your &lt;strong&gt;conf.py&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:group:&lt;/code&gt; This will tell the backend to group different images together.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Figure
&lt;/h2&gt;

&lt;p&gt;You can enlarge images on click using this directive, but the zoom in effect is not as smooth as the Thumbnail one. This is a built-in feature in Sphinx though so you don't need to install any extensions first.&lt;/p&gt;

&lt;p&gt;Example of using the Figure directive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;..&lt;/span&gt; &lt;span class="n"&gt;figure&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="n"&gt;px&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;auto&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;some&lt;/span&gt; &lt;span class="n"&gt;alt&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;

 &lt;span class="n"&gt;_insert&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="n"&gt;caption&lt;/span&gt; &lt;span class="n"&gt;here_&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see above, you can directly insert image captions with figure as long as it's still indented right under the &lt;code&gt;.. figure::&lt;/code&gt; directive (remember, ReST is very sensitive to indentation!).&lt;/p&gt;

&lt;h2&gt;
  
  
  Image
&lt;/h2&gt;

&lt;p&gt;This can be your last resort if, for some reason, those two directives do not work. However, in practice you can use this for when you need to reuse the same image in different pages of your documentation. This means, you can insert the image by simply using a pre-defined keyword.&lt;/p&gt;

&lt;p&gt;For example, you want to insert an inline icon in the same sentence.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;click the &lt;strong&gt;Exit&lt;/strong&gt; button |button-icon| to close the application&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;in the same file, preferably at the bottom of the file you can define the image substitution as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;..&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;button&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;icon&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;
  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and voila! you'll have an inline icon in your output. :) &lt;/p&gt;

&lt;p&gt;That's all! Enjoy working with Sphinx. Ciao Kakao.&lt;/p&gt;

</description>
      <category>python</category>
      <category>sphinx</category>
      <category>restructured</category>
      <category>rest</category>
    </item>
  </channel>
</rss>
