<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Your Next Tech Partner]]></title><description><![CDATA[Your Next Tech Partner]]></description><link>https://blog.yntp.me</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 10:57:38 GMT</lastBuildDate><atom:link href="https://blog.yntp.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Git & Github: A Beginner's Guide]]></title><description><![CDATA[Crash Course Overview
If you want to get started on learning about Git technology, you’ve come to the right place. This is a comprehensive beginner’s guide to Git.
Git and GitHub are two technologies that every developer should learn, irrespective of...]]></description><link>https://blog.yntp.me/git-and-github-crash-course</link><guid isPermaLink="true">https://blog.yntp.me/git-and-github-crash-course</guid><category><![CDATA[Git]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Akash Kadlag]]></dc:creator><pubDate>Fri, 12 Aug 2022 05:32:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1659696916578/sLYJQsQfz.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-crash-course-overview">Crash Course Overview</h3>
<p>If you want to get started on learning about Git technology, you’ve come to the right place. This is a comprehensive beginner’s guide to Git.</p>
<p>Git and GitHub are two technologies that every developer should learn, irrespective of their field. If you're a beginner developer, you might think that these two terms mean the same thing – but they're different.</p>
<p>This Crash Course will help you understand what Git and version control are, the basic Git commands you need to know, how you can use its features to boost your work efficiency, and how to extend these features using GitHub.</p>
<h1 id="heading-prerequisite">Prerequisite</h1>
<p>To get the most out of this article, we need the following:</p>
<ul>
<li><p>A command line interface.</p>
</li>
<li><p>A text editor of your choice (I will be using VS Code).</p>
</li>
<li><p>A GitHub account.</p>
</li>
</ul>
<h1 id="heading-what-is-version-control-system">What is Version Control System...?</h1>
<p>Version Control Systems are software tools for tracking/managing all the changes made to the source code during the project development. It keeps a record of every single change made to the code. It also allows us to turn back to the previous version of the code if any mistake is made in the current version.</p>
<p>Without a VCS in place, it would not be possible to monitor the development of the project.</p>
<ul>
<li><h3 id="heading-types-of-vcs">Types of VCS</h3>
<p>  The three types of VCS are:</p>
<ol>
<li><p><strong>Local Version Control System</strong></p>
<p> Local Version Control System is located in your local machine. If the local machine crashes, it would not be possible to retrieve the files, and all the information will be lost. If anything happens to a single version, all the versions made after that will be lost.</p>
</li>
<li><p><strong>Centralized Version Control System</strong></p>
<p> In the Centralized Version Control Systems, there will be a single central server that contains all the files related to the project, and many collaborators checkout files from this single server (you will only have a working copy). The problem with the Centralized Version Control Systems is if the central server crashes, almost everything related to the project will be lost.</p>
</li>
<li><p><strong>Distributed Version Control System</strong></p>
<p> In a distributed version control system, there will be one or more servers and many collaborators similar to the centralized system. But the difference is, not only do they check out the latest version, but each collaborator will have an exact copy (mirroring) of the main repository(including its entire history) on their local machines.</p>
<p> Each user has their own repository and a working copy. This is very useful because even if the server crashes we would not lose everything as several copies are residing in several other computers.</p>
</li>
</ol>
</li>
</ul>
<h1 id="heading-what-is-git">What is Git...?</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1659780743355/_7WtBsxvn.png" alt="git.png" class="image--center mx-auto" /></p>
<p>Git is a distributed version control system designed to track changes in a project’s files. Git was released in 2005 by Linus Torvalds.</p>
<p>With Git, you can revert to various states of your files (like a time-traveling machine). You can also make a copy of your file, make changes to that copy, and then merge these changes to the original copy.</p>
<p>Real-life projects generally have multiple developers working in parallel. So they need a version control system like Git to make sure that there are no code conflicts between them.</p>
<ul>
<li><h3 id="heading-why-you-should-learn-and-use-git">Why you should learn and use git?</h3>
<p>  More than 87% of developers use Git as a control system. Any developer needs at least a base knowledge of Git to be successful and relevant to the market.</p>
<p>  Most companies, big and small, use Git as a repository, including:</p>
<ul>
<li><p>Netflix</p>
</li>
<li><p>Reddit</p>
</li>
<li><p>Lyft</p>
</li>
<li><p>Shopify</p>
</li>
<li><p>Facebook</p>
</li>
<li><p>Atlasssian</p>
</li>
<li><p>Google</p>
</li>
<li><p>eBay</p>
</li>
</ul>
</li>
</ul>
<ul>
<li><h3 id="heading-git-workflow">Git Workflow</h3>
<p>  Before we start working with Git commands, it is necessary that you understand what it represents.</p>
<p>  A repository a.k.a. repo is nothing but a collection of source code.</p>
<p>  There are four fundamental elements in the Git Workflow.</p>
<p>  Working Directory, Staging Area, Local Repository, and Remote Repository.</p>
<p>  If you consider a file in your Working Directory, it can be in three possible states.</p>
<ol>
<li><p><em>It can be staged.</em></p>
<p> This means the files with the updated changes are marked to be committed to the local repository but not yet committed.</p>
</li>
<li><p><em>It can be modified.</em></p>
</li>
</ol>
</li>
</ul>
<p>    This means the files with the updated changes are not yet stored in the local repository.</p>
<ol start="3">
<li><em>It can be committed.</em></li>
</ol>
<p>    This means that the changes you made to your file are safely stored in the local repository.</p>
<p>    <code>git add</code> is a command used to add a file that is in the working directory to the staging area.</p>
<p>    <code>git commit</code> is a command used to add all files that are staged to the local repository.</p>
<p>    <code>git push</code> is a command used to add all committed files in the local repository to the remote repository. So in the remote repository, all files and changes will be visible to anyone with access to the remote repository.</p>
<p>    <code>git fetch</code> is a command used to get files from the remote repository to the local repository but not into the working directory.</p>
<p>    <code>git merge</code> is a command used to get the files from the local repository into the working directory.</p>
<p>    <code>git stash</code> is used temporarily to store modified, tracked files in order to change branches.</p>
<p>    <code>git pull</code> is a command used to get files from the remote repository directly into the working directory. It is equivalent to a git fetch and a git merge.</p>
<h1 id="heading-get-started-with-git">Get started with Git</h1>
<p>The Git software is a powerful command-line tool that you can install on your machine, whether you use Windows, macOS, or Linux.</p>
<ul>
<li><h3 id="heading-installing-git">Installing Git</h3>
<p>  <strong>If you are on a Mac</strong>, fire up the terminal and enter the following command:</p>
<pre><code class="lang-bash">  $ git --version
</code></pre>
<p>  This will prompt open an installer if you don’t already have git. So set it up using the installer. If you have git already, it’ll just show you which version of git you have installed.</p>
<p>  <strong>If you are running Linux(deb)</strong>, enter the following in the terminal:</p>
<pre><code class="lang-bash">  $ sudo apt install git-all
</code></pre>
<p>  <strong>If you are on Windows</strong>:</p>
<pre><code class="lang-bash">  $ get a mac 🙂
</code></pre>
<p>  Just kidding… Relax… The number of people I triggered… Phew… Go to this <a target="_blank" href="https://www.apple.com/mac/">link</a> or this <a target="_blank" href="https://git-scm.com/download/win">official website</a> for more info on how to get it.</p>
</li>
<li><h3 id="heading-first-time-configuration">First time Configuration</h3>
<p>  The <code>git config</code> command allows you to set configuration variables that control how git looks and operates. The <code>config</code> command works on different levels:</p>
<ol>
<li><p><strong>Local-level</strong>: This means that all your credentials and configurations are only limited to your project’s directory. By default, git config writes to a local level when no configuration is passed.</p>
</li>
<li><p><strong>Global-level</strong>: this configuration is specific to a user on the operating system; the configuration values live in the user’s home directory.</p>
</li>
<li><p><strong>System-level</strong>: These configurations are placed in the system’s root path; it tracks all users and all repos on the operating system.</p>
</li>
</ol>
</li>
</ul>
<p>    The first thing you configure after a successful installation is your email address and username; this will identify our contributions and changes in the project source code. To set up your user name and email, run the following in your command line:</p>
<pre><code class="lang-bash">git config --global user.name <span class="hljs-string">"YOUR_USERNAME"</span>
</code></pre>
<pre><code class="lang-bash">git config --global user.email <span class="hljs-string">"YOUR_EMAIL_ADDRESS"</span>
</code></pre>
<p>Git is a powerful tool, but some of the functionality is tied to having a text editor that can update settings, configure changes, or modify the contents of files. Because the defaults may not match your preferences, it’s important to specify the editor you want to use and the commands required to use it.</p>
<p>Personally, I enjoy using Visual Studio Code, so I use the following global default:</p>
<pre><code class="lang-bash">git config --global core.editor <span class="hljs-string">"code --wait"</span>
</code></pre>
<p>Git offers differential treatment for line endings of files, in Windows &amp; Linux. It is important to set the proper line endings for your git repository if you need to make it cross platform. If you don’t set line endings for your git commits, then the repository code will not work when checked out on another platform.</p>
<p>The simplest ways to configure line endings is to us git config command. Here is an example:</p>
<p><strong>For Mac</strong></p>
<pre><code class="lang-bash">git config --global core.autocrlf input
</code></pre>
<p><strong>For Windows</strong></p>
<pre><code class="lang-bash">git config --global core.autocrlf <span class="hljs-literal">true</span>
</code></pre>
<p>To check the info you just provided, run the following in your command line:</p>
<pre><code class="lang-bash">$ git config --global --list
</code></pre>
<h1 id="heading-what-is-github">What is GitHub...?</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1659780639988/rwx5nA4PC.png" alt="github.png" class="image--center mx-auto" /></p>
<p>GitHub is a platform that can be used to host code online. Think of GitHub as a platform that stores the whole codebase in a remote repository. It comes with tools to collaborate on projects of any size.</p>
<p>GitHub lets you store your repo on their platform. Another awesome feature that comes with GitHub is the ability to collaborate with other developers from any location.</p>
<ul>
<li><h3 id="heading-why-you-should-learn-and-use-github">Why you should learn and use GitHub?</h3>
<ol>
<li><p><strong>Git makes it easy to contribute to open source projects</strong></p>
<p> Nearly every open-source project uses GitHub to manage their projects. Using GitHub is free if your project is open source, and it includes a wiki and issue tracker that makes it easy to include more in-depth documentation and get feedback about your project.</p>
<p> If you want to contribute, you just fork (get a copy of) a project, make your changes, and then send the project a pull request using GitHub's web interface. This pull request is your way of telling the project you're ready for them to review your changes.</p>
</li>
<li><p><strong>Documentation</strong></p>
<p> By using GitHub, you make it easier to get excellent documentation. Their help section and guides have articles for nearly any topic related to Git that you can think of.</p>
</li>
<li><p><strong>Integration options</strong></p>
<p> GitHub can integrate with common platforms such as Amazon and Google Cloud, with services such as Code Climate to track your feedback, and can highlight syntax in over 200 different programming languages.</p>
</li>
<li><p><strong>Track changes in your code across versions</strong></p>
<p> When multiple people collaborate on a project, it’s hard to keep track of revisions — who changed what, when, and where those files are stored.</p>
<p> GitHub takes care of this problem by keeping track of all the changes that have been pushed to the repository.</p>
</li>
<li><p><strong>Showcase your work</strong></p>
<p> Are you a developer who wishes to attract recruiters? GitHub is the best tool you can rely on for this. Today, when searching for new recruits for their projects, most companies look at GitHub profiles. If your profile is available, you will have a higher chance of being recruited even if you are not from a great university or college.</p>
</li>
</ol>
</li>
</ul>
<h1 id="heading-get-started-with-github">Get Started with GitHub</h1>
<p>To create your account, you need to go to <a target="_blank" href="https://github.com">GitHub's website</a> and fill out the registration form.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1659799985079/HfFIcTv7v.JPG" alt="Screenshot 2022-08-06 at 9.02.43 PM.JPG" class="image--center mx-auto" /></p>
<h1 id="heading-lets-git">Let's Git</h1>
<ul>
<li><h3 id="heading-creating-remote-repo"><strong>Creating Remote Repo</strong></h3>
<p>  Create a new repository on GitHub. Follow <a target="_blank" href="https://github.com/new">this link</a>.</p>
<p>  <strong>Step 1</strong>: Click on new</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1659933467542/bo3vetwZP.JPG" alt="Screenshot 2022-08-08 at 10.03.44 AM.JPG" class="image--center mx-auto" /></p>
<p>  <strong>Step 2</strong>: Click on create repository</p>
<p>  Give your repository a name, and description(optional), choose if you want to make it a public or a private repo(only you and the people you give access can see a private repo), and you can also add a readme and a license if you want. Otherwise, leave all that options as it is and click create repository.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1659933501834/VI1rbYFUc.JPG" alt="Screenshot 2022-08-08 at 10.06.37 AM.JPG" class="image--center mx-auto" /></p>
<p>  ✨Your repo is created</p>
</li>
<li><h3 id="heading-creating-local-repo"><strong>Creating Local Repo</strong></h3>
<p>  I have created a folder on my desktop called git-and-github-tutorial. Using the command line, navigate to your new project's location. For me, I would run the following commands:</p>
<pre><code class="lang-bash">  $ <span class="hljs-built_in">cd</span> Desktop/git-and-github-tutorial
</code></pre>
<p>  If you are new to the command line and are still learning how to use it to navigate around your PC, then I would suggest using Microsoft's Visual Studio Code. It is a code editor which has an inbuilt terminal for executing commands. You can <a target="_blank" href="https://code.visualstudio.com/download">download it here</a>.</p>
<p>  After installing VS Code, open your project in the editor and open a new terminal for your project. This automatically points the terminal/command line to your project's path.</p>
</li>
<li><h3 id="heading-initialize-git"><strong>Initialize Git</strong></h3>
<p>  Git is present in your system, but it is sleeping and it'll remain asleep until you'll wake him up. To wake him up and tell him to start working on a project, you have to use a command inside that project folder in the command prompt.</p>
<p>  To wake Git up, the command is:</p>
<pre><code class="lang-bash">  $ git init
</code></pre>
<p>  Running this command would initialize an empty Git repository in the current directory. A new subfolder named .git is created which contains several files and more subdirectories that Git will use to keep track of changes in the project.</p>
</li>
<li><h3 id="heading-git-project-files"><strong>Git Project Files</strong></h3>
<p>  Let’s create the first file that we will be tracking using Git. Ensure you are still in the git-and-github-tutorial directory on your terminal, then run the following command:</p>
<pre><code class="lang-bash">  touch sample.txt
</code></pre>
<p>  This will create a file named sample with the .txt extension.</p>
<p>  Open the file in your editor and add the following lines to it:</p>
<pre><code class="lang-plaintext">  This is sample text.
</code></pre>
<p>  Save and close this file.</p>
</li>
<li><h3 id="heading-add-files-to-the-staging-area-for-commit"><strong>Add files to the Staging Area for commit:</strong></h3>
<p>  Now to add the files to the git repository for commit:</p>
<pre><code class="lang-bash">  $ git add .
</code></pre>
<p>  The above command Adds all the files in the local repository and stages them for commit</p>
<p>  OR if you want to add a specific file like this:</p>
<pre><code class="lang-bash">  $ git add sample.txt
</code></pre>
</li>
<li><h3 id="heading-before-we-commit-lets-see-what-files-are-staged"><strong>Before we commit let’s see what files are staged:</strong></h3>
<pre><code class="lang-bash">  $ git status
</code></pre>
<p>  The above command will list all new or modified files to be committed.</p>
</li>
<li><h3 id="heading-commit-changes-you-made-to-your-git-repo"><strong>Commit Changes you made to your Git Repo:</strong></h3>
<p>  Next, you need to make a commit with an accompanying commit message. Commit messages are short descriptive messages describing what changes were made.</p>
<p>  Let’s commit the file that’s currently staged by running the following command: git commit -m "add sample.txt"</p>
<pre><code class="lang-bash">  git commit -m <span class="hljs-string">"add sample.txt"</span>
</code></pre>
<p>  This command saves a new commit with the message “add sample.txt”. Now, when you run <code>git status</code>, you will get a message indicating that your working tree is clean (no modified or untracked files).</p>
</li>
<li><h3 id="heading-way-to-uncommit-changes-you-just-made-to-your-git-repo"><strong>Way to Uncommit Changes you just made to your Git Repo:</strong></h3>
<p>  Now suppose you just made some error in your code or placed an unwanted file inside the repository, you can unstage the files you just added using:</p>
<pre><code class="lang-bash">  $ git reset HEAD~1
  <span class="hljs-comment"># Remove the most recent commit</span>
  <span class="hljs-comment"># Commit again!</span>
</code></pre>
</li>
<li><h3 id="heading-ignoring-files"><strong>Ignoring Files</strong></h3>
<p>  Sometimes there are untracked files that you would not like to add to your git index. These may be user-specific configuration files, like a .env file, or folders with large files, like the vendor folder for PHP projects or node_modules in JavaScript projects.</p>
<p>  You can instruct git to ignore these files by adding glob patterns to a <code>.gitignore</code> file. This file will live in your project’s root directory and can contain any number of patterns. Any untracked file or folder that matches a pattern specified in the <code>.gitignore</code> file is ignored by git.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660209191660/W10WZK461.JPG" alt="Screenshot 2022-08-11 at 2.10.21 PM.JPG" class="image--center mx-auto" /></p>
<p>  So in the above example, files like <strong>pycache</strong>, .DS_Store are used by the system to store information for faster access. This is not useful for other collaborators. So we can tell git to ignore them by adding a .gitignore file.</p>
<p>  Use the touch command to create the .gitignore file:</p>
<pre><code class="lang-bash">  $ touch .gitignore
</code></pre>
<p>  And you can add the following patterns to tell git to ignore such files.</p>
<pre><code class="lang-text">  /*.cmake
  /*.DS_Store
  /.user
  /build

  # Config files
  .env
  .env.local
  /.vscode

  # Large folders
  /node_modules
  /vendor
</code></pre>
<p>  Each line in a <code>.gitignore</code> file specifies a pattern. Lines that begin with a # sign are comments. The patterns here are similar to what you would typically see in a PHP or JavaScript project.</p>
<p>  The following are examples of patterns used in a <code>.gitignore</code> file:</p>
<ul>
<li><p>*.env matches all files with a .env extension</p>
</li>
<li><p>/vendor matches the folder named vendor, as well as its subfolders and files</p>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>build_output.log would match the .log file named build_output.</p>
</li>
<li><h3 id="heading-connect-remote-repo-with-local-repo"><strong>Connect Remote Repo with Local Repo:</strong></h3>
<p>  Now each time you make changes in your files and save them, they won’t be automatically updated on GitHub. All the changes we made in the file are updated in the local repository. Now to update the changes to the master:</p>
<pre><code class="lang-bash">   $ git remote add origin remote_repository_URL
   <span class="hljs-comment"># sets the new remote</span>
</code></pre>
<p>  The git remote command lets you create, view, and delete connections to other repositories.</p>
<pre><code class="lang-plaintext">  $ git remote -v
  # List the remote connections you have to other repositories.
</code></pre>
<p>  The git remote -v command lists the URLs of the remote connections you have to other repositories.</p>
</li>
<li><h3 id="heading-pushing-code-to-github"><strong>Pushing code to GitHub</strong></h3>
<p>  Once we have added the remote repository URL to our local one, we will want to push or upload our local code and its revision history to the remote repository. This can be done using <code>git push</code>.</p>
<p>  The <code>git push</code> command will update the remote repository code with all the updates that were made in the local repository.</p>
<p>  First, commit the <code>.gitignore</code> file we created earlier.</p>
<pre><code class="lang-bash">  git add .
  git commit -m <span class="hljs-string">"add .gitignore"</span>
</code></pre>
<p>  You can run the following command to push your code to the remote repository:</p>
<pre><code class="lang-bash">  git push -u origin master
</code></pre>
<p>  And there you have it. You have successfully pushed your code to a remote repository.</p>
</li>
</ul>
<h1 id="heading-how-to-use-branches-in-git">How to Use Branches in Git</h1>
<p>Git branching is a very powerful feature and an important one to know. We talked about Git's superpower to create identical copies of your project, and allow you to work on them separately; Git achieves this through branching.</p>
<p>With branches, you can create a copy of a file you would like to work on without messing up the original copy. You can either merge these changes to the original copy or just let the branch remain independent.</p>
<p>Before we go into using branches, I want to show you a visual representation of our repo which looks like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660212568482/oP7dJ_jyt.png" alt="g638.png" class="image--center mx-auto" /></p>
<p>The image above shows our main branch with the last two commits (add sample.txt and the add .gitignore commit).</p>
<p>At this point, I want to make more changes but I am not yet sure whether I want them on main code. So I will create a new branch called test to see how would project look like with new changes.</p>
<p>To check branches in your project:</p>
<pre><code class="lang-bash">git branch
</code></pre>
<p>To create a new branch, run this command:</p>
<pre><code class="lang-bash">git checkout -b <span class="hljs-built_in">test</span>.
</code></pre>
<p>I will break it down. <code>checkout</code> tells Git it is supposed to switch to a new branch. <code>-b</code> tells Git to create a new branch. <code>test</code> is the name of the branch to be created and switched to.</p>
<p>Now that we have a new branch created, this is what our repo will look like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660213587509/LJJP3krOF.png" alt="g664.png" class="image--center mx-auto" /></p>
<p>We created the new branch from the state of our last commit. Let's let's make some changes to this new branch.</p>
<pre><code class="lang-bash">touch README.md
git commit -am <span class="hljs-string">"Add README file"</span>
</code></pre>
<p>To merge the new state to the main branch, you have to first stage and commit this branch. I will not go into details about how to do this as we did it twice in the last section.</p>
<p>You should try doing it yourself so you understand how it works. As a hint, add the file and then commit with a message (refer to the previous section for details showing you how to do that).</p>
<p>After committing your test branch, switch back to the main branch by running this command:</p>
<pre><code class="lang-bash">git checkout main.
</code></pre>
<p>Did you notice that we did not add -b ? This is because we are not creating a new branch but rather switching to an existing one.</p>
<p>Now we can merge the changes we made in the test branch into the main branch by running git merge test. At this point, you will see all the changes made in the test branch reflected on the main branch.</p>
<p>Here is a visual representation of our repo:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660214925731/5Z2-Y6rfz.png" alt="g816.png" class="image--center mx-auto" /></p>
<p>If you go on to push your repo to GitHub, you'll see that the test branch will not be pushed. It will only remain in your local repo. If you would like to push your test branch, switch to the branch using git checkout test and then run git push -u origin test.</p>
<h1 id="heading-open-source-tips">Open-Source Tips</h1>
<ul>
<li><p>Always make a separate branch when you working with a new feature or fixing a bug in someone's else repository.</p>
</li>
<li><p>HEAD : It's just a pointer that means all the commits that you've made will be added on the head(the new branch).</p>
</li>
<li><p>To check when someone else commits to the main branch.</p>
<pre><code class="lang-bash">  git checkout main
</code></pre>
</li>
<li><p>For merging your code with the main code.</p>
<pre><code class="lang-bash">  git merge [branch-name]
</code></pre>
</li>
<li><p>For copying existing organization project use <code>fork</code> for that</p>
</li>
<li><p>clone that project in your repository.</p>
<pre><code class="lang-bash">  git <span class="hljs-built_in">clone</span> [URL] (paste the URL of the forked project)
</code></pre>
</li>
<li><p>upstream URL: It's the URL from where you've forked the project.</p>
<pre><code class="lang-bash">  git remote add upstream [URL]
</code></pre>
</li>
<li><p>To make changes in the upstream (original project)</p>
<p>  make a new branch</p>
<pre><code class="lang-bash">  git checkout -b [new-branch]
</code></pre>
</li>
<li><p>For making changes in the original project of the organization we use pull request.</p>
</li>
<li><p>NOTE: One Branch for One pull request We always make a new branch to make it easier to review our commit to the original project.</p>
</li>
</ul>
<h1 id="heading-bonus-section-important-git-commands">Bonus Section - Important Git Commands</h1>
<p><strong>git init</strong></p>
<p>Initializes an existing directory as Git repository (.git directory).</p>
<pre><code class="lang-bash">git init
</code></pre>
<p>**git clone **</p>
<p>Retrieve an entire repository from a hosted location via URL.</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> [url]
</code></pre>
<p><strong>git add</strong></p>
<p>add a file to your next commit(stage).</p>
<pre><code class="lang-bash">git add [file]
</code></pre>
<p><strong>git rm</strong></p>
<p>Deletes the file from project and stages the removal for commit.</p>
<pre><code class="lang-bash">git rm [file]
</code></pre>
<p><strong>git mv</strong></p>
<p>Changes an existing file path and stages the move.</p>
<pre><code class="lang-bash">git mv [existing-path][new-path]
</code></pre>
<p><strong>git commit</strong></p>
<p>Commits the staged contents as a new commit snapshot.</p>
<pre><code class="lang-bash">git commit -m <span class="hljs-string">"your commit message goes here"</span>
</code></pre>
<p><strong>git branch</strong></p>
<p>List, Create or, Delete Branches(branches looks like an acyclic graph)</p>
<ul>
<li><p>List branches</p>
<pre><code class="lang-bash">  git branch
</code></pre>
</li>
<li><p>Create a new Branch at the current commit</p>
<pre><code class="lang-bash">  git branch [branch-name]
</code></pre>
</li>
<li><p>Delete a Branch</p>
<pre><code class="lang-bash">  git branch -d[branch-name]
</code></pre>
</li>
</ul>
<p><strong>git status</strong></p>
<p>Shows the paths of modified files in working directory.</p>
<pre><code class="lang-bash">git status
</code></pre>
<p><strong>git diff</strong></p>
<p>Show changes between commits.</p>
<ul>
<li><p>to see diff of what is changed, but not staged</p>
<pre><code class="lang-bash">  git diff
</code></pre>
</li>
<li><p>to see diff of what is staged, but not commited</p>
<pre><code class="lang-bash">  git diff --staged
</code></pre>
</li>
<li><p>to see diff between 2 branches</p>
<pre><code class="lang-bash">  git diff BranchA...BranchB
</code></pre>
</li>
</ul>
<p><strong>git log</strong></p>
<p>Shows the commit history for the currently active branch.</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span>
</code></pre>
<p><strong>git checkout</strong></p>
<ul>
<li><p>Switch Branches. Switch to another branch and, check it out into your working directory .</p>
<pre><code class="lang-bash">  git checkout [branch-name]
</code></pre>
</li>
<li><p>Switch to another branch(create if does not exist)</p>
<pre><code class="lang-bash">  git checkout -b [branch-name]
</code></pre>
</li>
</ul>
<p><strong>git merge</strong></p>
<p>For joining two or more development histories together.</p>
<pre><code class="lang-bash">git merge [branch]
</code></pre>
<p><strong>git fetch</strong></p>
<p>Fetch branches and/or tags from one or more other repositories.</p>
<pre><code class="lang-bash">git fetch [<span class="hljs-built_in">alias</span>]
</code></pre>
<p>You can use git fetch to know the changes done in the remote rep/branch since your last pull.</p>
<p><strong>git pull</strong></p>
<p>Fetch and merge any commits from the tracking of a remote branch.</p>
<pre><code class="lang-bash">git pull
</code></pre>
<p><strong>git push</strong></p>
<ul>
<li><p>For making changes in your repository</p>
<pre><code class="lang-bash">  git push origin [branch-name]
</code></pre>
</li>
<li><p>Transmit local branch commits to the remote repository branch.</p>
<pre><code class="lang-bash">  git push [<span class="hljs-built_in">alias</span>]
</code></pre>
</li>
</ul>
<p><strong>git rebase</strong></p>
<p>Applies any commits of the current branch ahead of the specified one. It is used if you need to rewrite the history of a project.</p>
<pre><code class="lang-bash">git rebase [branch-name]
</code></pre>
<p><strong>git revert</strong></p>
<p>Reverts some existing commits.</p>
<pre><code class="lang-bash">git revert
</code></pre>
<p><strong>git reset</strong></p>
<ul>
<li><p>If you want to delete the commits.</p>
<pre><code class="lang-bash">  git reset [hashcodeId]
</code></pre>
<p>  you can get "haschodeId" by running <code>git log</code> (NOTE: the commits deleted will be in an unstaged area)</p>
</li>
<li><p>Resets current HEAD to the specified state.</p>
<p>  Unstages a file while retaining the changes in working directory.</p>
<pre><code class="lang-bash">  git reset [file]
</code></pre>
<p>  (NOTE: the commits deleted will be in unstaged area)</p>
</li>
<li><p>Clears staging area, rewrites working tree from specified commit.</p>
<pre><code class="lang-bash">  git reset --hard[commit]
</code></pre>
</li>
</ul>
<p><strong>git stash</strong></p>
<p>Temporarily stores modified, tracked files in order to change branches. It's used when you don't want to commit your working files but wants to store them temporarily.</p>
<ul>
<li><p>Save modified and staged changes</p>
<pre><code class="lang-bash">  git stash
</code></pre>
</li>
<li><p>List StackOrder of stashed file changes</p>
<pre><code class="lang-bash">  git stash list
</code></pre>
</li>
<li><p>Write working from the top of the stash stack or bring your temporarily stored files.</p>
<pre><code class="lang-bash">  git stash pop
</code></pre>
</li>
<li><p>Discard the changes from top</p>
<pre><code class="lang-bash">  git stash drop
</code></pre>
</li>
<li><p>For deleting temporary stored, modified, and tracked files.</p>
<pre><code class="lang-bash">  git stash clear
</code></pre>
</li>
</ul>
<p><strong>git remote</strong></p>
<ul>
<li><p>For adding the URL of your repository to your project</p>
<pre><code class="lang-plaintext">  git remote add origin [URL]
</code></pre>
<p>  Remote means you're working with URLs and origin is the name of the URL.</p>
</li>
<li><p>Shows all the URLs attached with your project</p>
<pre><code class="lang-bash">  git remote -v
</code></pre>
</li>
</ul>
<h1 id="heading-in-closing">In closing</h1>
<p>I hope that you’ve found this tutorial helpful...! If you have any questions or feedback, feel free to leave a comment below.</p>
<p>If you found this article helpful, please like and share it 💙.</p>
<p>That's all for today! 😁 You reached the end of the article 😍.</p>
<h2 id="heading-other-resources">Other Resources</h2>
<p>Check out some of these resources for a more in-depth look into Git and GitHub :</p>
<ul>
<li><p><a target="_blank" href="https://education.github.com/git-cheat-sheet-education.pdf">Git CheetSheet</a></p>
</li>
<li><p><a target="_blank" href="https://youtu.be/apGV9Kg7ics">Complete Git and GitHub Tutorial</a></p>
</li>
<li><p><a target="_blank" href="https://youtu.be/3fUbBnN_H2c">Git and GitHub Tutorial For Beginners</a></p>
</li>
<li><p><a target="_blank" href="https://youtu.be/8JJ101D3knE">Learn Git in 1 Hour</a></p>
</li>
</ul>
<h2 id="heading-want-more">Want more..?</h2>
<p>I write articles on <a target="_blank" href="https://blog.yntp.me">blog.yntp.me</a>, and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/yntpdotme">Twitter/X</a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/yntpdotme"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Mastering CSS Position in 2022.]]></title><description><![CDATA[Confused with CSS Position...?
In this article, I will be breaking down all CSS position properties and explaining everything you need to know about them. This includes even the more obscure concepts related to the position that most articles/videos ...]]></description><link>https://blog.yntp.me/mastering-css-position</link><guid isPermaLink="true">https://blog.yntp.me/mastering-css-position</guid><category><![CDATA[CSS]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Akash Kadlag]]></dc:creator><pubDate>Fri, 29 Jul 2022 13:03:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1661260154393/kzMKEjyTE.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-confused-with-css-position">Confused with CSS Position...?</h3>
<p>In this article, I will be breaking down all CSS position properties and explaining everything you need to know about them. This includes even the more obscure concepts related to the position that most articles/videos ignore.</p>
<h1 id="heading-prerequisite">Prerequisite</h1>
<p>To get the most out of this article, we need the following:</p>
<ul>
<li><p>Basic understanding of HTML.</p>
</li>
<li><p>Basic understanding of CSS. (check out <a target="_blank" href="https://akashkadlag.hashnode.dev/mastering-css-selectors">CSS Selctors</a>)</p>
</li>
<li><p>Visual studio code or any IDE of our choice to code along.</p>
</li>
</ul>
<h1 id="heading-css-positions">CSS Positions</h1>
<p>When building a webpage, there can be multiple elements on our page, each with their own positions, uses, and designs. It’s important to learn how we can arrange these elements and have control over their layout.</p>
<p>The position property in CSS determines how an element is positioned in a document. It specifies the type of positioning method for each element.</p>
<h1 id="heading-values-of-css-positions">Values of CSS Positions</h1>
<p>The position property can have any of these values:</p>
<ul>
<li><p>static</p>
</li>
<li><p>absolute</p>
</li>
<li><p>relative</p>
</li>
<li><p>fixed</p>
</li>
<li><p>sticky</p>
</li>
</ul>
<p>You can also specify the value of <code>inherit</code>, which means the value is determined from the parent element. The position value doesn’t cascade, so this can be used to specifically force it to, and inherit the positioning value from its parent.</p>
<h1 id="heading-placement-properties">Placement Properties</h1>
<p>Position property on its own is not that useful. It only says how the position should be calculated. For example, relative to the normal position of an element.</p>
<p>But we also need to define where exactly the element should be placed, not only how. There are several properties we can use for that.</p>
<ul>
<li><p>top</p>
</li>
<li><p>left</p>
</li>
<li><p>right</p>
</li>
<li><p>bottom</p>
</li>
<li><p>z-index</p>
</li>
</ul>
<p>These define how much the element's position should be adjusted and in which direction.</p>
<h1 id="heading-normal-flow">Normal Flow</h1>
<p>Before going into details, let's see how these elements automatically get their position on your page. To understand this, you need to understand the normal flow of the web page. Normal flow is how the elements are arranged on a page if you haven't changed their layout.</p>
<p>There are two types of elements on a web page. Block-level elements and inline elements.</p>
<p>Block-level elements such as <code>&lt;h1&gt;</code>, <code>&lt;div&gt;</code>, <code>&lt;p&gt;</code> are contained on their own line. Because block-level elements start with a line break, two block-level elements can't exist on the same line without styling.</p>
<p>Inline elements such as <code>&lt;a&gt;</code>, <code>&lt;img&gt;</code>, <code>&lt;span&gt;</code>, don't form their own blocks. Instead, they are displayed within lines. They line up next to one another horizontally; when there isn't enough space left on the line, the content moves to a new line.</p>
<h1 id="heading-static-position">Static Position</h1>
<p><code>position: static</code> is the default value provided by HTML. This means if we don’t declare position for an element in CSS, it will automatically be set to static.</p>
<p>Even though it is a default value, it can sometimes be useful to set it explicitly. For example, to override different position value, which is set elsewhere.</p>
<p>Elements that are statically positioned will follow the normal document flow and will position itself based on the standard positioning rules.</p>
<p>Unlike with other position values, when using <code>static</code>, placement properties such as <code>top</code>, <code>left</code>, <code>bottom</code>, <code>right</code>, or <code>z-index</code> have no effect.</p>
<p><strong>Example to illustrate Static Position :</strong></p>
<p>We are using the following HTML markup:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent"</span>&gt;</span>
    Parent
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"one"</span>&gt;</span>
      One <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
      position:static <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
      top: 50px ( this has no effect )
   <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"two"</span>&gt;</span>Two<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"three"</span>&gt;</span>Three<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>And here’s the CSS we’re using:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.parent</span> { 
   // No position set, so it's static 
} 
<span class="hljs-selector-class">.one</span> { 
   // No position set, so it's static 
   <span class="hljs-attribute">top</span>: <span class="hljs-number">50px</span>; 
}
</code></pre>
<p>However, here is how it will look on a webpage:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1658756921292/8UFyGALXz.JPG" alt="Screenshot 2022-07-25 at 7.17.38 PM.JPG" class="image--center mx-auto" /></p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/YzaxxbP">Codepen</a></p>
<p>Since both elements have a static position, none of the layout CSS properties will do anything. This makes the top property have no effect on how the element with class="one" is displayed.</p>
<h1 id="heading-relative-position">Relative Position</h1>
<p>Relative position means that the element is placed relative to its original position in the page. A <code>relative</code> position element works exactly the same as <code>static</code> position, but you can now add <code>z-index</code>, <code>top</code>, <code>left</code>, <code>right</code>, and <code>bottom</code> properties to it.</p>
<p>If you make an element <code>relative</code> positioned without setting any of these extra properties you will notice it looks exactly the same as a static positioned element. This is because <code>relative</code> positioned elements also follow the normal document flow, but you can offset them using the <code>top</code>, <code>left</code>, <code>right</code>, and <code>bottom</code> properties.</p>
<p><strong>Example to illustrate Relative Position :</strong></p>
<p>We are using the following HTML markup:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent"</span>&gt;</span>
    Parent
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"one"</span>&gt;</span>One<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"two"</span>&gt;</span>Two<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"three"</span>&gt;</span>Three<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>And here’s the CSS we’re using:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.one</span> {
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">15px</span>;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">15px</span>;
}
</code></pre>
<p>However, here is how it will look on a webpage:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1658757495117/1V2_mPpNX.JPG" alt="Screenshot 2022-07-25 at 7.27.44 PM.JPG" class="image--center mx-auto" /></p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/ZExJazz">Codepen</a></p>
<p>As a result of an element being moved from its original position, there can be a situation, where multiple elements overlap each other. Fortunately, with <code>z-index</code> property, you can control which elements should be in the front and which in the back. We'll discuss this in more detail later.</p>
<p>Only <code>relative</code> position is not that useful as you do not usually want to offset an element without also moving all the elements around it. The main use cases for position <code>relative</code> are to either set the <code>z-index</code> of the element, or to be used as a container for <code>absolute</code> positioned elements which we will talk about next.</p>
<h1 id="heading-absolute-position">Absolute Position</h1>
<p>The <code>absolute</code> position completely removes the element from the normal document flow. If you give an element position <code>absolute</code> all other elements will act as if the <code>absolute</code> positioned element doesn't even exist.</p>
<p>An element using <code>position: absolute</code> is positioned relative to the nearest ancestor. In other words, an element with <code>position: absolute</code> is positioned relative to its parent element.</p>
<p>If an element doesn’t have a parent element, it’s placed relative to its initial containing block. It can then be positioned by the values of top, right, bottom, and left.</p>
<blockquote>
<p>Note : If we don’t specify helper properties, it’s positioned automatically to the starting point (top-left corner) of its parent element.</p>
</blockquote>
<p><strong>Example to illustrate Absolute Position :</strong></p>
<p>We are using the following HTML markup:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent"</span>&gt;</span>
    Parent
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"one"</span>&gt;</span>One<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"two"</span>&gt;</span>Two<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"three"</span>&gt;</span>Three<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>And here’s the CSS we’re using:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.parent</span> {
  <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.one</span> {
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">right</span>: <span class="hljs-number">0</span>;
}
</code></pre>
<p>However, here is how it will look on a webpage:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1658761720014/_FII-qujq.JPG" alt="Screenshot 2022-07-25 at 8.38.13 PM.JPG" /></p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/OJvjzmV">Codepen</a></p>
<p>By setting the blue parent element to a position of relative I am now forcing the absolute positioned child one element to be in the top right corner of the parent instead of the body. This combination of relative and absolute positions is incredibly common.</p>
<h1 id="heading-fixed-position">Fixed Position</h1>
<p>The <code>fixed</code> position is a bit like <code>absolute</code> position in that it removes the element out of the normal flow, but <code>fixed</code> position elements are always positioned in the same place in the viewport (what’s visible on screen). This means that scrolling will not affect its position at all.</p>
<p><strong>Example to illustrate Fixed Position :</strong></p>
<p>We are using the following HTML markup:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent"</span>&gt;</span>
    Parent
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"one"</span>&gt;</span>One<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"two"</span>&gt;</span>
       Two <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
       Ha ha! Scrolling can't get rid of me!!
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"three"</span>&gt;</span>Three<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>And here’s the CSS we’re using:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.two</span> {
  <span class="hljs-attribute">position</span>: fixed;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">right</span>: <span class="hljs-number">0</span>;
}
</code></pre>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/PoRKEMG">https://codepen.io/KadlagAkash/pen/PoRKEMG</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/PoRKEMG">Codepen</a></p>
<p>The pink fixed element will stay positioned at the top and right corner of the viewport. And if you scroll, the blue parent element and other child elements will scroll up normally, but the pink element will remain stuck to where we positioned it.</p>
<blockquote>
<p>Tip: A fixed element must have a top or bottom position set. If it doesn’t, it will simply not exist on the page at all.</p>
</blockquote>
<p>You have to be careful with <code>fixed</code> position usage. On a mobile device with a small screen, it can be a big deal if a large portion of your screen is always covered with a navigation bar or something similar. It dramatically reduces space for the actual content of your page and can significantly limit usability.</p>
<h1 id="heading-sticky-position">Sticky Position</h1>
<p>The <code>sticky</code> position is a combination of both <code>fixed</code> and <code>relative</code> position and combines the best of them both.</p>
<p>An element with position sticky will act like a <code>relative</code> positioned element until the page scrolls to a point where the element hits the <code>top</code>, <code>left</code>, <code>right</code>, or <code>bottom</code> value specified. It will then act like a fixed position element and scroll with the page until the element gets to the end of its container.</p>
<blockquote>
<p>In other words, elements set with <code>position: sticky</code> are positioned based on the user’s scroll position.</p>
</blockquote>
<p>As of this writing, it is currently an experimental value, meaning it is not part of the official spec and is only partially adopted by select browsers. In other words, it’s probably not the best idea to use this on a live production website.</p>
<p><strong>Example to illustrate Sticky Position :</strong></p>
<p>We are using the following HTML markup:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent"</span>&gt;</span>
    Parent
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"one"</span>&gt;</span>One<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"two"</span>&gt;</span>
       Two <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
       I stick at the top <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
       position: sticky <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
       top: 0px;
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"three"</span>&gt;</span>Three<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>And here’s the CSS we’re using:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.two</span> {
  <span class="hljs-attribute">position</span>: sticky;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
}
</code></pre>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/eYMEQJm">https://codepen.io/KadlagAkash/pen/eYMEQJm</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/eYMEQJm">Codepen</a></p>
<p><code>sticky</code> position is the perfect position for navbars that scroll with the page, headings in long lists, and many other use cases.</p>
<h1 id="heading-z-index">Z-index</h1>
<p>When working with position other than static, elements can easily appear in position, where they overlap each other.</p>
<p>This is where the <code>z-index</code> property comes in. When you have elements overlapping, we use <code>z-index</code> to stack them. It controls the position of your elements on the z-axis.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1658799878872/eQpzRJ_t8.webp" alt="agY_-dPfE.jpeg.webp" class="image--center mx-auto" /></p>
<p>You can use <code>z-index</code> like this:</p>
<pre><code class="lang-css"> <span class="hljs-selector-tag">z-index</span>: 1;
</code></pre>
<p>The <code>z-index</code> gives you the ability to decide how the elements should overlap each other, in which order. If you give a higher <code>z-index</code> value, that particular element will appear closer to the viewer. In other words, it will appear on top of the other elements.</p>
<p><strong>Example to illustrate Z-index:</strong></p>
<p>We are using the following HTML markup:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"parent"</span>&gt;</span>
    Parent
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"one"</span>&gt;</span>One<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"two"</span>&gt;</span>
       Two <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
       I stick at the top <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
       position: sticky <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
       top: 0px;
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"three"</span>&gt;</span>Three<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>And here’s the CSS we’re using:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.first</span>{
  <span class="hljs-attribute">z-index</span>: <span class="hljs-number">3</span>;
}

<span class="hljs-selector-class">.second</span>{
  <span class="hljs-attribute">z-index</span>: <span class="hljs-number">2</span>;
}

<span class="hljs-selector-class">.third</span>{
  <span class="hljs-attribute">z-index</span>: <span class="hljs-number">1</span>;
}

<span class="hljs-selector-class">.four</span>{
  <span class="hljs-comment">/* No z-index */</span>
}

<span class="hljs-selector-class">.fifth</span>{
  <span class="hljs-attribute">z-index</span>: -<span class="hljs-number">1</span>;
}
</code></pre>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/jOzLQGg">https://codepen.io/KadlagAkash/pen/jOzLQGg</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/jOzLQGg">Codepen</a></p>
<h1 id="heading-summary">Summary</h1>
<p>Let's sum it up. The <code>position</code> property allows you to determine how elements should be placed on the page.</p>
<p>You can define the exact location using <code>top</code>, <code>bottom</code>, <code>right</code> and <code>left</code> properties.</p>
<p>In case your elements overlap each other, you can change their order using <code>z-index</code>. The higher the index, the closer is the element to the user.</p>
<p><strong>static</strong></p>
<ul>
<li><p>Default value</p>
</li>
<li><p>Positioning as usual, same as if you didn't specify the position</p>
</li>
</ul>
<p><strong>relative</strong></p>
<ul>
<li><p>The element is placed relative to its normal position on the page</p>
</li>
<li><p>The place occupied by the element is preserved at its original location</p>
</li>
</ul>
<p><strong>absolute</strong></p>
<ul>
<li><p>The element is removed from the normal flow and does not occupy space</p>
</li>
<li><p>The location is determined relative to the first parent set position (other than <code>static</code>)</p>
</li>
<li><p>If there is no such parent, it is determined relative to the whole page.</p>
</li>
</ul>
<p><strong>fixed</strong></p>
<ul>
<li><p>The element is removed from the normal flow and does not occupy space</p>
</li>
<li><p>The location is determined relative to the viewport</p>
</li>
<li><p>Elements keep their locations as you scroll</p>
</li>
</ul>
<p><strong>sticky</strong></p>
<ul>
<li><p>Elements are positioned relatively until you reach them by scrolling</p>
</li>
<li><p>Then the elements stick to one location, similar to fixed positioning</p>
</li>
<li><p>Not supported by all the browsers, you can check out the current support on <a target="_blank" href="https://caniuse.com/css-sticky">CanIUse.com</a>.</p>
</li>
</ul>
<h1 id="heading-in-closing">In closing</h1>
<p>I hope that you’ve found this tutorial and code examples on CSS positioning helpful...! If you have any questions or feedback, feel free to leave a comment below.</p>
<p>If you found this article helpful, please like and share it 💙.</p>
<p>That's all for today! 😁 You reached the end of the article 😍.</p>
<h2 id="heading-other-resources">Other Resources</h2>
<p>Check out some of these resources for a more in-depth look into CSS Positions :</p>
<ul>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/position">MDN CSS Positions</a></p>
</li>
<li><p><a target="_blank" href="https://youtu.be/jx5jmI0UlXU">WDS CSS Positions</a></p>
</li>
<li><p><a target="_blank" href="https://css-tricks.com/almanac/properties/p/position/">CSS Positions</a></p>
</li>
</ul>
<h2 id="heading-want-more">Want more..?</h2>
<p>I write articles on <a target="_blank" href="https://yntp.me">blog.yntp.me</a>, and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://twitter.com/yntpdotme">Twitter/X</a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/yntpdotme"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Mastering CSS & CSS3 Selectors in 2022.]]></title><description><![CDATA[Save time searching for the CSS selectors.
This blog will look at the different types of CSS selectors and how we can use them to build efficient CSS code.
Prerequisite
To get the most out of this article, we need the following:

Basic understanding ...]]></description><link>https://blog.yntp.me/mastering-css-selectors</link><guid isPermaLink="true">https://blog.yntp.me/mastering-css-selectors</guid><category><![CDATA[CSS]]></category><category><![CDATA[CSS3]]></category><category><![CDATA[iwritecode]]></category><category><![CDATA[Learn Code Online]]></category><category><![CDATA[BlogsWithCC]]></category><dc:creator><![CDATA[Akash Kadlag]]></dc:creator><pubDate>Tue, 26 Jul 2022 10:06:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1658494474490/dqBrhI4mw.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-save-time-searching-for-the-css-selectors">Save time searching for the CSS selectors.</h3>
<p>This blog will look at the different types of CSS selectors and how we can use them to build efficient CSS code.</p>
<h1 id="heading-prerequisite">Prerequisite</h1>
<p>To get the most out of this article, we need the following:</p>
<ul>
<li><p>Basic understanding of HTML.</p>
</li>
<li><p>Visual studio code or any IDE of our choice to code along.</p>
</li>
</ul>
<h1 id="heading-css-selectors">CSS Selectors</h1>
<p>CSS selectors are the opening part of a CSS ruleset. CSS Selectors are used to targeting specific elements on the web page.</p>
<p>CSS selectors are case-sensitive. They must match element names and attribute values precisely. For Example, <strong>.logo</strong> <em>class selector is not the same as</em> <strong>.LOGO</strong>.</p>
<p>It is advisable to use small letters to avoid making mistakes.</p>
<p><strong>The syntax for CSS Selector is:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">selector</span> {
   <span class="hljs-attribute">CSS-property</span>: value;
}
</code></pre>
<h1 id="heading-types-of-css-selectors">Types of CSS Selectors</h1>
<ul>
<li><p>Basic Selectors</p>
</li>
<li><p>Combination Selectors</p>
</li>
<li><p>Attribute Selector</p>
</li>
<li><p>Pseudo Element Selector</p>
</li>
<li><p>Pseudo Class Selector</p>
</li>
</ul>
<h1 id="heading-basic-css-selectors">Basic CSS Selectors</h1>
<p>Basic CSS selectors are the most common type of CSS selectors. They style specific elements on a website. In basic selectors, we have selectors such as:</p>
<ul>
<li><h3 id="heading-universal-selector">Universal Selector</h3>
<p>  I refer to this selector as the god selector, the mother of all selectors, one selector to rule them all. That is how powerful it is.</p>
<p>  The universal selector selects every tag on the page so we can style every tag or element with one rule.</p>
<p>  The asterisk (*) character represents Universal selectors.</p>
<p>  <strong>The syntax for Universal Selector is:</strong></p>
<pre><code class="lang-css">  * {
    <span class="hljs-attribute">CSS-Property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Universal Selector:</strong></p>
<pre><code class="lang-css">  * {
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">outline</span>: <span class="hljs-number">0</span>;
  }
</code></pre>
<p>  In the above ⬆️ example, we override the default styling applied by browsers.</p>
</li>
<li><h3 id="heading-element-type-selector">Element Type Selector</h3>
<p>  Type Selectors are the most common basic CSS selectors. They select HTML elements based on the element name.</p>
<p>  The Element type selector selects all instances of a tag or element on a page.</p>
<p>  <strong>The syntax for Element Type Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">element</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Element Type Selector:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>; 
  }
</code></pre>
<p>  In the above ⬆️ example, all paragraph <code>&lt;p&gt;</code> elements will align to the center, and have a font size of 20px.</p>
<p>  However, here is how it will look on a webpage:  </p>
</li>
</ul>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/OJvjaqG">https://codepen.io/KadlagAkash/pen/OJvjaqG</a></div>
<p> </p>
<p>    View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/OJvjaqG">Codepen</a></p>
<ul>
<li><h3 id="heading-class-selector">Class Selector</h3>
<p>  The class selector is probably the most useful and versatile selector. The class selector is best used when you want to reuse a style for multiple elements.</p>
<p>  To select elements with a specific class, write a period (.) character, followed by the class name.</p>
<p>  <strong>The syntax for Class Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-class">.class-name</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Class Selector:</strong></p>
<p>  In the example below ⬇️ the <code>&lt;p&gt;</code> element has a class="text"</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>Text goes here....<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>  To select the <code>&lt;p&gt;</code> element using the CSS class selector, we:</p>
<pre><code class="lang-css">  <span class="hljs-selector-class">.text</span> {
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>; 
  <span class="hljs-attribute">color</span>: skyblue;
  }
</code></pre>
<p>  All HTML element with class="text" will align to the center, have blue text color and a font-size of 20px.  </p>
<p>  However, here is how it will look on a webpage:  </p>
<p>  %[https://codepen.io/KadlagAkash/pen/xxWLQoP] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/xxWLQoP">Codepen</a></p>
</li>
<li><h3 id="heading-id-selector">ID Selector</h3>
<p>  ID attributes are specific to one element only. The ID selector identifies an element based on its ID attribute.</p>
<p>  To select an element with a specific ID, write a hash (#) character, followed by the element's ID.</p>
<p>  This selector is the most powerful in terms of CSS Specificity.</p>
<p>  <strong>The syntax for ID Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-id">#id-name</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of ID Selector:</strong></p>
<p>  In the example below ⬇️, the <code>&lt;p&gt;</code> element has an id="tagline"</p>
<pre><code class="lang-html">  Tagline goes here....
</code></pre>
<p>  To select the element using the ID selector, we: <code>css #tagline { text-align: center; font-size: 25px; font-style: italic; color: red; letter-spacing: 2px; }</code><br />In the example above ⬆️, the CSS rule will apply to the HTML element with id="tagline".</p>
</li>
</ul>
<p>However, here is how it will look on a webpage:
%[https://codepen.io/KadlagAkash/pen/WNzELNv] </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/WNzELNv">Codepen</a></p>
<p>\&gt; <em>Use ID selectors rarely and only on elements that need always to appear the same.</em></p>
<h1 id="heading-combination-css-selectors">Combination CSS Selectors</h1>
<p>Combination Selectors select elements based on a specific relationship between them. In Combination selectors, we have selectors such as:</p>
<ul>
<li><h3 id="heading-descendant-selector">Descendant Selector</h3>
<p>  Descendant selectors match all elements that are descendants of a specified element. Descendant selectors select the children, grandchildren, etc., when used.</p>
<p>  It uses the white space as a separator between the elements.</p>
<p>  <strong>The syntax for Descendant Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector1</span> <span class="hljs-selector-tag">selector2</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Descendant Selector:</strong></p>
<p>  In the example below ⬇️, the <code>&lt;div&gt;</code> element has multiple nested <code>&lt;p&gt;</code> elements.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 2.1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 2.2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 3<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>  To select all <code>&lt;p&gt;</code> elements using the descendant selector, we use:</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">div</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">font-style</span>: italic; 
  <span class="hljs-attribute">color</span>: teal;
  }
</code></pre>
<p>  In the example above ⬆️, the CSS rule will apply to the <code>&lt;p&gt;</code> child elements of <code>&lt;div&gt;</code>.</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/mdxMaQy] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/mdxMaQy">Codepen</a></p>
</li>
<li><h3 id="heading-direct-child-selector">Direct Child Selector</h3>
<p>  Direct Child Selector selects all the specified direct children of the parent.</p>
<p>  Like a descendant selector, the direct child selector is for selecting child elements. Still, the main difference is the direct child selector will only select an element that is the direct child of the first parent selector.</p>
<p>  We use the greater-than sign (&gt;) character to represent a child selector.</p>
<p>  <strong>The syntax for Direct Child Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">Parent-selector</span> &gt; <span class="hljs-selector-tag">Child-selector</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Direct Child Selector:</strong></p>
<p>  In the example below ⬇️, the <code>&lt;div&gt;</code> element has multiple nested <code>&lt;p&gt;</code> elements.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 2.1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 2.2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 3<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>  To select all <code>&lt;p&gt;</code> elements using the direct child selector, we use:</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">div</span> &gt; <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">font-style</span>: italic; 
  <span class="hljs-attribute">color</span>: lightgreen;
  }
</code></pre>
<p>  In the example above ⬆️, the CSS rule will apply to the only <code>&lt;p&gt;</code> elements that are a direct child of <code>&lt;div&gt;</code>.</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/BardvEL] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/BardvEL">Codepen</a></p>
</li>
<li><h3 id="heading-adjacent-sibling-selector">Adjacent Sibling Selector</h3>
<p>  The Adjacent sibling selects an element directly after another specific element.</p>
<p>  In other words, this selector selects the elements that follow and share the same parent. They must immediately follow each other.</p>
<p>  The tilde (+) character represents adjacent sibling selectors.</p>
<p>  <strong>The syntax for Adjacent Sibling Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">first-sibling-selector</span> + <span class="hljs-selector-tag">second-sibling-selector</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  The second sibling element comes after the first sibling element and it's the targeted element. The targeted element is the element you intend to style.</p>
<p>  <strong>Example of Adjacent Sibling Selector:</strong></p>
<p>  In the example below ⬇️ the <code>&lt;div&gt;</code> element has <code>&lt;p&gt;</code> elements and <code>&lt;ul&gt;</code> elements that consist of multiple <code>&lt;li&gt;</code> elements.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"red"</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 4<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>  To select <code>&lt;li&gt;</code> that comes immediately after <code>&lt;li&gt;</code> element of class="red" using the general sibling selector, we use:</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">li</span><span class="hljs-selector-class">.red</span> + <span class="hljs-selector-tag">li</span> {
    <span class="hljs-attribute">background</span>: red;
  }
</code></pre>
<p>  In the example above ⬆️, the CSS rule will apply to the ltem 3.</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/OJvjdPb] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/OJvjdPb">Codepen</a></p>
</li>
<li><h3 id="heading-general-sibling-selector">General Sibling Selector</h3>
<p>  General Sibling Selector selects all specified HTML elements that are placed after another specified element and they must be children of the same parent element.</p>
<p>  In other words, this selector selects the elements that follow and share the same parent. It is not necessary that the second element immediately follows the first element.</p>
<p>  The tilde (~) character represents general sibling selectors.</p>
<p>  <strong>The syntax for General Sibling Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">first-sibling-selector</span> ~ <span class="hljs-selector-tag">second-sibling-selector</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  The second sibling element comes after the first sibling element and it's the targeted element. The targeted element is the element you intend to style.</p>
<p>  <strong>Example of General Sibling Selector:</strong></p>
<p>  In the example below ⬇️ the <code>&lt;div&gt;</code> element has <code>&lt;p&gt;</code> elements and <code>&lt;ul&gt;</code> elements that consist of multiple <code>&lt;li&gt;</code> elements.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"red"</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item 4<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Paragraph 2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>  To select all <code>&lt;li&gt;</code> that comes after <code>&lt;li&gt;</code> element of class="red" using the general sibling selector, we use:</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">li</span><span class="hljs-selector-class">.red</span> ~ <span class="hljs-selector-tag">li</span> {
  <span class="hljs-attribute">background</span>: red;
  }
</code></pre>
<p>  In the example above ⬆️, the CSS rule will apply to only ltem 3 and Item 4.</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/WNzEPvZ] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/WNzEPvZ">Codepen</a></p>
</li>
<li><h3 id="heading-or-selector">Or Selector</h3>
<p>  Or selector allows us to select multiple elements with different selectors at once and style them. This is done by grouping them in a comma-separated list and CSS selects all the matching elements in the list.</p>
<p>  It reduces the time of writing same code for multiple times for similar elements.</p>
<blockquote>
<p><strong>Note</strong> : <em>When you group selectors in this way, If any selector is invalid the whole rule will be ignored.</em></p>
</blockquote>
<p>  <strong>The syntax for Or Selector is:</strong></p>
</li>
</ul>
<p>selector1, selector2, ... { property: value; }</p>
<pre><code class="lang-plaintext">**Example of Or Selector:**

Suppose we need to apply border-radius to .btn-primary and .btn-secondary

Instead of doing this:
```css
.btn-primary{ 
  border-radius : 3px;  
}
.btn-secondary{
  border-radius : 3px;
}
</code></pre>
<p>Use Or selector :</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.btn-primary</span>, <span class="hljs-selector-class">.btn-secondary</span> {
    <span class="hljs-attribute">border-radius </span>: <span class="hljs-number">3px</span>;
}
</code></pre>
<p>In the example above ⬆️, the CSS rule will apply to both <code>&lt;button&gt;</code> elements having class of "btn-primary" and "btn-secondary".</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/YzaxBYW">https://codepen.io/KadlagAkash/pen/YzaxBYW</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/YzaxBYW">Codepen</a></p>
<ul>
<li><h3 id="heading-and-selector">And Selector</h3>
<p>  Sometimes we want to use specific elements for styling. Here, the selector comes into action.</p>
<p>  Suppose we have <code>&lt;p&gt;</code> element and <code>&lt;a&gt;</code> element having the same class = "img" and we have to specify that a class should affect only an HTML <code>&lt;p&gt;</code> element, then we use And Selector.</p>
<p>  And Selector Select elements that match all the selector combinations</p>
<p>  <strong>Example of ID Selector:</strong></p>
<p>  In the example below ⬇️ the <code>&lt;p&gt;</code> and <code>&lt;a&gt;</code> element has a class="img"</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./images/image.jpg"</span> <span class="hljs-attr">class</span>= <span class="hljs-string">"img"</span>/&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"img"</span>&gt;</span>Description of Image....<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"http://www.example.com/image.jpg"</span> <span class="hljs-attr">download</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"img"</span>&gt;</span>Download<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>  For example, to select an element with a specific class, write a period (.), followed by the element's class name.</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">p</span><span class="hljs-selector-class">.img</span> {
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">color</span>: green;
  }
</code></pre>
<p>  In the example above ⬆️, the CSS rule will apply to the <code>&lt;p&gt;</code> element with class="img".</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/NWYvoMY] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/NWYvoMY">Codepen</a></p>
</li>
</ul>
<h1 id="heading-attribute-css-selectors">Attribute CSS Selectors</h1>
<p>Attribute selectors select all elements that have a given attribute or attribute value. We include attributes in an HTML element's opening tag. In Attribute selectors, we have selectors such as:</p>
<ul>
<li><h3 id="heading-has-attribute">Has Attribute</h3>
<p>  Has attribute selector select elements with a specified attribute.</p>
<p>  <strong>The syntax for Has Attribute Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-attr">[attribute]</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Has Attribute Selector:</strong></p>
<p>  In the example below ⬇️ the <code>&lt;a&gt;</code> element has attributes like href and target.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>Click Here<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>  Styling the above ⬆️ HTML <code>&lt;a&gt;</code> element:</p>
</li>
</ul>
<p>a[target]{ font-size: 20px; color: yellow; text-decoration: none; } <code>In the example above ⬆️, the CSS rule will apply to the</code>``` element which has the attribute of the target.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/YzaxBdN">https://codepen.io/KadlagAkash/pen/YzaxBdN</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/YzaxBdN">Codepen</a></p>
<ul>
<li><h3 id="heading-exact-attribute">Exact Attribute</h3>
<p>  Exact attribute selector selects elements with a specified attribute and value.</p>
<p>  The equals (=) character represents the Exact attribute selectors.</p>
<p>  <strong>The syntax for Exact Attribute Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-attr">[attribute=<span class="hljs-string">"value"</span>]</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Exact Attribute Selector:</strong></p>
<p>  In the example below ⬇️, the <code>&lt;a&gt;</code> element has attributes like href and target.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://google.com"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>Google<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>  Styling the above ⬆️ HTML <code>&lt;a&gt;</code> element:</p>
</li>
</ul>
<p>a[href="https://google.com"]{ font-size: 20px; color: yellow; text-decoration: none; } <code>In the example above ⬆️, the CSS rule will apply to the</code>``` element which has the attribute of href="https://google.com".</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/yLKoZww">https://codepen.io/KadlagAkash/pen/yLKoZww</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/yLKoZww">Codepen</a></p>
<ul>
<li><h3 id="heading-begins-with-attribute">Begins With Attribute</h3>
<p>  Begins with attribute selector select elements whose attribute value begins with a specific value.</p>
<p>  The circumflex accent (^) character represents Begins with attribute selector.</p>
<p>  <strong>The syntax for Begins with Attribute Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-attr">[attribute^=<span class="hljs-string">"value"</span>]</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Begins with Attribute Selector:</strong></p>
<p>  In the example below ⬇️ the <code>&lt;a&gt;</code> element has attributes like href and target.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://google.com"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>Google<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>  Styling the above ⬆️ HTML <code>&lt;a&gt;</code> element:</p>
</li>
</ul>
<p>a[href^="https://"]{ font-size: 20px; color: yellow; text-decoration: none; } <code>In the example above ⬆️, the CSS rule will apply to the</code>``` element which has the attribute of href begins with "https://".</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/abYyXrv">https://codepen.io/KadlagAkash/pen/abYyXrv</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/abYyXrv">Codepen</a></p>
<ul>
<li><h3 id="heading-end-with-attribute">End With Attribute</h3>
<p>  Ends with attribute selector select elements whose attribute value ends with a specific value.</p>
<p>  The dollar sign ($) character represents Ends with attribute selector.</p>
<p>  <strong>The syntax for Ends with Attribute Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-attr">[attribute$=<span class="hljs-string">"value"</span>]</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Ends with Attribute Selector:</strong></p>
<p>  In the example below ⬇️, the <code>&lt;a&gt;</code> element has attributes like href and target.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"http://www.example.com/image.jpg"</span> <span class="hljs-attr">download</span>" <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>Get Stunning Image<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>  Styling the above ⬆️ HTML <code>&lt;a&gt;</code> element:</p>
</li>
</ul>
<p>a[href$=".jpg"]{ font-size: 20px; color: yellow; text-decoration: none; } <code>In the example above ⬆️, the CSS rule will apply to the</code>``` element which has the attribute of href ends with ".jpg".</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/OJvjdYv">https://codepen.io/KadlagAkash/pen/OJvjdYv</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/OJvjdYv">Codepen</a></p>
<ul>
<li><h3 id="heading-substring-attribute">Substring Attribute</h3>
<p>  Substring Attribute Selector selects elements whose attribute value contains a specified value.</p>
<p>  The asterisk (*) character represents the substring attribute selector.</p>
<p>  <strong>The syntax for Substring Attribute Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-attr">[attribute*=<span class="hljs-string">"value"</span>]</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Substring Attribute Selector:</strong></p>
<p>  In the example below ⬇️ the <code>&lt;div&gt;</code> element has an attribute of data-red.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">data-red</span>=<span class="hljs-string">"1234"</span>&gt;</span>This is Div<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>  Styling the above ⬆️ HTML <code>&lt;div&gt;</code> element:</p>
</li>
</ul>
<p>div[data-red*="23"]{ font-size: 20px; color: lightgreen; text-decoration: none; } <code>In the example above ⬆️, the CSS rule will apply to the</code></p>
<p>``` element which has the attribute of data-red that contains "23".</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/xxWLMvZ">https://codepen.io/KadlagAkash/pen/xxWLMvZ</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/xxWLMvZ">Codepen</a></p>
<h1 id="heading-pseudo-element-selectors">Pseudo Element Selectors</h1>
<h2 id="heading-1-textual-pseudo-elements">1. Textual Pseudo Elements</h2>
<ul>
<li><h3 id="heading-first-letter-selector">First-Letter Selector</h3>
<p>  The first-letter selector applies a style to the first letter of the element.</p>
<blockquote>
<p><strong>Note</strong> : The ::first-letter pseudo-element work only for block elements.</p>
</blockquote>
<p>  <strong>The syntax for First-Letter Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">::first-letter</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of First-Letter Selector:</strong></p>
<p>  In the example below ⬇️, there is a sample paragraph in the <code>&lt;div&gt;</code> element.</p>
</li>
</ul>
<p>This is Sample Text.</p>
<p>``` Styling the above ⬆️ HTML ```</p>
<p>``` element: ```css p::first-letter{ font-size: 50px; font-weight: 900; padding: 0 3px; } ``` In the example above ⬆️, the CSS rule will apply to the first letter of the ```</p>
<p>``` element.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/gOexEpe">https://codepen.io/KadlagAkash/pen/gOexEpe</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/gOexEpe">Codepen</a></p>
<ul>
<li><h3 id="heading-first-line-selector">First-Line Selector</h3>
<p>  The first-line selector applies a style to the first line of the element.</p>
<blockquote>
<p><strong>Note</strong> : The ::first-line pseudo-element work only for block elements.</p>
</blockquote>
<p>  <strong>The syntax for First-Line Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">::first-line</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of First-Line Selector:</strong></p>
<p>  In the example below ⬇️, there is a sample paragraph in the <code>&lt;div&gt;</code> element.</p>
</li>
</ul>
<p>This is Sample Text.<br />Here we are demonstrating usage of pseudo elements</p>
<p>``` Styling the above ⬆️ HTML ```</p>
<p>``` element: ```css p::first-line{ background-color: orange; color: black; } ``` In the example above ⬆️, the CSS rule will apply to the first line of```</p>
<p>``` element.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/vYRJPLe">https://codepen.io/KadlagAkash/pen/vYRJPLe</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/vYRJPLe">Codepen</a></p>
<h2 id="heading-2-generated-content-pseudo-elements">2. Generated Content Pseudo Elements</h2>
<ul>
<li><h3 id="heading-before-selector">Before Selector</h3>
<p>  The Before Selector adds content before the HTML element.</p>
<blockquote>
<p><strong>Note</strong> : When using the ::before pseudo-element, we must use the content property to make our styles visible.</p>
</blockquote>
<p>  <strong>The syntax for Before Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">::before</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Before Selector:</strong></p>
<p>  In the example below ⬇️ there is sample paragraph in <code>&lt;div&gt;</code> element.</p>
</li>
</ul>
<p>This is Sample Text.</p>
<p>``` Styling the above ⬆️ HTML ```</p>
<p>``` element: ```css p::before{ content: "content"; background: red; } ``` In the example above ⬆️, the CSS rule will add content with red background before ```</p>
<p>``` element.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/yLKowJm">https://codepen.io/KadlagAkash/pen/yLKowJm</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/yLKowJm">Codepen</a></p>
<ul>
<li><h3 id="heading-after-selector">After Selector</h3>
<p>  The After Selector adds content after the HTML element.</p>
<blockquote>
<p><strong>Note</strong> : When using the ::after pseudo-element, we must use the content property to make our styles visible.</p>
</blockquote>
<p>  <strong>The syntax for After Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">::after</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of After Selector:</strong></p>
<p>  In the example below ⬇️, there is a sample paragraph in the <code>&lt;div&gt;</code> element.</p>
</li>
</ul>
<p>This is Sample Text.</p>
<p>``` Styling the above ⬆️ HTML ```</p>
<p>``` element: ```css p::after{ content: "content"; background: blue; } ``` In the example above ⬆️, the CSS rule will add content with blue background after the ```</p>
<p>``` element.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/OJvjqRw">https://codepen.io/KadlagAkash/pen/OJvjqRw</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/OJvjqRw">Codepen</a></p>
<h1 id="heading-pseudo-class-selectors">Pseudo Class Selectors</h1>
<h2 id="heading-1-pseudo-class-state-selectors">1. Pseudo Class State Selectors</h2>
<ul>
<li><h3 id="heading-hover-selector">Hover Selector</h3>
<p>  The Hover Selector selects elements that are hovered by the mouse.</p>
<p>  :hover works when the user moves their cursor over an element but does not select it.</p>
<p>  <strong>The syntax for Hover Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">:hover</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of Hover Selector:</strong></p>
<p>  In the example below ⬇️, there is a sample paragraph in the <code>&lt;a&gt;</code> element.</p>
</li>
</ul>
<p>Hover on this link: <a class="post-section-overview" href="#">click</a></p>
<p>``` Styling the above ⬆️ HTML `````` element: ```css a:hover{ color: black; background: orange; } ``` In the example above ⬆️, the CSS rule will apply to the `````` element when we hover over it.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/YzaxgEe">https://codepen.io/KadlagAkash/pen/YzaxgEe</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/YzaxgEe">Codepen</a></p>
<ul>
<li><h3 id="heading-focus-selector">Focus Selector</h3>
<p>  The Focus Selector selects an element that is being focused on by the user. "focused on by the user" means it accepts the keyboard or any other user input.</p>
<p>  It works on user input elements used in forms and is triggered when the user clicks on it.</p>
<p>  <strong>The syntax for Focus Selector is:</strong></p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">:focus</span> {
   <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p>  <strong>Example of focus Selector:</strong></p>
<p>  In the example below ⬇️, there is <code>&lt;input&gt;</code> element.</p>
</li>
</ul>
<p>``` Styling the above ⬆️ HTML `````` element: ```css input:focus { background: orange; } ``` In the example above ⬆️, the CSS rule will apply to `````` element when we focus on it.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/WNzEmzq">https://codepen.io/KadlagAkash/pen/WNzEmzq</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/WNzEmzq">Codepen</a></p>
<ul>
<li><h3 id="heading-required-selector">Required Selector</h3>
<p>  The Required Selector selects inputs that are required.</p>
<blockquote>
<p><strong>Note</strong> : The :required selector only applies to the form elements: input, select and textarea.</p>
</blockquote>
<p>  <strong>The syntax for Required Selector is:</strong></p>
</li>
</ul>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">:required</span> {
     <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p><strong>Example of Required Selector:</strong></p>
<p>In the example below ⬇️, there is <code>&lt;input&gt;</code> element. <code>html &lt;input type="text" required placeholder="Required Field"/&gt;</code> Styling the above ⬆️ HTML <code>&lt;input&gt;</code> element: <code>css input:required { color: red; }</code> In the example above ⬆️, the CSS rule will apply to the <code>&lt;input&gt;</code> element which is required to fill.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/yLKowqY">https://codepen.io/KadlagAkash/pen/yLKowqY</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/yLKowqY">Codepen</a></p>
<ul>
<li><h3 id="heading-checked-selector">Checked Selector</h3>
<p>  The Checked Selector selects checkboxes/radio buttons that are checked.</p>
<p>  The checked selector matches every checked element (only for radio buttons and checkboxes) and element.</p>
<p>  <strong>The syntax for Checked Selector is:</strong></p>
</li>
</ul>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">:checked</span> {
     <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p><strong>Example of Checked Selector:</strong></p>
<p>In the example below ⬇️, there is <code>&lt;input&gt;</code> element. <code>html &lt;input type="radio" checked="checked" value="male" name="gender"/&gt; Male&lt;br/&gt; &lt;input type="radio" value="female" name="gender"/&gt; Female&lt;br/&gt; &lt;input type="checkbox" checked="checked" value="Bike"/&gt; I have a bike&lt;br/&gt; &lt;input type="checkbox" value="Car"/&gt; I have a car</code> Styling the above ⬆️ HTML <code>&lt;input&gt;</code> element: <code>css input:checked { height: 30px; width: 30px; }</code> In the example above ⬆️, the CSS rule will apply to <code>&lt;input&gt;</code> element which are checked.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/poLrYQj">https://codepen.io/KadlagAkash/pen/poLrYQj</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/poLrYQj">Codepen</a></p>
<ul>
<li><h3 id="heading-disabled-selector">Disabled Selector</h3>
<p>  The Disabled Selector selects inputs that are disabled.</p>
<p>  <strong>The syntax for Disabled Selector is:</strong></p>
</li>
</ul>
<pre><code class="lang-css">  <span class="hljs-selector-tag">selector</span><span class="hljs-selector-pseudo">:disabled</span> {
     <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p><strong>Example of Disabled Selector:</strong></p>
<p>In the example below ⬇️ there is <code>&lt;input&gt;</code> element. ```html</p>
<p>First name:<br />Last name:<br />Country:</p>
<p>``` Styling the above ⬆️ HTML `````` element: ```css input[type=text]:disabled { background: #dddddd; } ``` In the example above ⬆️, the CSS rule will apply to `````` element of type="text" which are disabled.</p>
<p>However, here is how it will look on a webpage:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/KadlagAkash/pen/MWVvxLy">https://codepen.io/KadlagAkash/pen/MWVvxLy</a></div>
<p> </p>
<p>View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/MWVvxLy">Codepen</a></p>
<h2 id="heading-2-pseudo-class-position-selectors">2. Pseudo Class Position Selectors</h2>
<ul>
<li><h3 id="heading-first-child-selector">First-Child Selector</h3>
<p>  The First-Child Selector applies a style to the element's first child.</p>
<p>  <strong>The syntax for First-Child Selector is:</strong></p>
</li>
</ul>
<pre><code class="lang-css">   <span class="hljs-selector-pseudo">:first-child</span> {
     <span class="hljs-attribute">property</span>: value;
  }
</code></pre>
<p><strong>Example of First-Child Selector:</strong></p>
<p>In the example below ⬇️ there is <code>&lt;li&gt;</code> element. ```html</p>
<ul>
<li><p>This is first child</p>
</li>
<li><p>This is second child</p>
</li>
<li><p>This is third child</p>
</li>
</ul>
<p>``` Styling the above ⬆️ HTML ```</p>
<ul>
<li><p>``` element: ```css ul li:first-child { color: red; font-weight: bold; } ``` In the example above ⬆️, the CSS rule will apply to the first element among a sibling group of ```</p>
</li>
<li><p>```elements.</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/qBoXvex] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/qBoXvex">Codepen</a></p>
<ul>
<li><h3 id="heading-last-child-selector">Last-Child Selector</h3>
<p>  The Last-Child Selector applies a style to the element's last child.</p>
<p>  <strong>The syntax for Last-Child Selector is:</strong></p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-css">       <span class="hljs-selector-pseudo">:last-child</span> {
         <span class="hljs-attribute">property</span>: value;
      }
</code></pre>
<p>    <strong>Example of Last-Child Selector:</strong></p>
<p>    In the example below ⬇️ there is <code>&lt;li&gt;</code> element. ```html</p>
<ul>
<li><p>Item 1</p>
</li>
<li><p>Item 2</p>
<ul>
<li><p>Item 2.1</p>
</li>
<li><p>Item 2.2</p>
</li>
</ul>
</li>
<li><p>Item 3</p>
</li>
<li><p>Item 4</p>
</li>
</ul>
<p>    <code>Styling the above ⬆️ HTML</code></p>
<ul>
<li><p><code>element:</code> css ul li:last-child { color: red; font-weight: bold; } <code>In the example above ⬆️, the CSS rule will apply to last element among a group of sibling</code></p>
</li>
<li><p>``` element i.e. Item 4 and Item 2.2</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/LYdjvYm] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/LYdjvYm">Codepen</a></p>
<ul>
<li><h3 id="heading-nth-child-selector">Nth-Child Selector</h3>
<p>  The Nth-Child Selector matches elements based on their position among a group of siblings.</p>
<p>  <strong>The syntax for Nth-Child Selector is:</strong></p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-css">       <span class="hljs-selector-pseudo">:nth-child(expression)</span> {
         <span class="hljs-attribute">property</span>: value;
      }
</code></pre>
<p>    Keyword values</p>
<p>    odd : Represents elements whose numeric position in a series of siblings is odd: 1, 3, 5, etc.</p>
<p>    even : Represents elements whose numeric position in a series of siblings is even: 2, 4, 6, etc.</p>
<p>    Functional notation :</p>
<p>    <code>&lt;An+B&gt;</code> Represents elements in a list whose indices match those found in a custom pattern of numbers, defined by An+B, where: A is an integer step size, B is an integer offset, n is all non-negative integers, starting from 0.</p>
<p>    It can be read as the An+Bth element of a list.</p>
<p>    <strong>Example of Last-Child Selector:</strong></p>
<p>    <code>tr:nth-child(odd)</code> or <code>tr:nth-child(2n+1)</code></p>
<p>    Represents the odd rows of an HTML table: 1, 3, 5, etc.</p>
<p>    <code>tr:nth-child(even)</code> or <code>tr:nth-child(2n)</code></p>
<p>    Represents the even rows of an HTML table: 2, 4, 6, etc.</p>
<p>    In the example below ⬇️ there is <code>&lt;li&gt;</code> element. ```html</p>
<ul>
<li><p>Item 1</p>
</li>
<li><p>Item 2</p>
<ul>
<li><p>Item 2.1</p>
</li>
<li><p>Item 2.2</p>
</li>
</ul>
</li>
<li><p>Item 3</p>
</li>
<li><p>Item 4</p>
</li>
</ul>
<p>    <code>Styling the above ⬆️ HTML</code></p>
<ul>
<li><p><code>element:</code> css ul li:nth-child(2n+1) { color: red; font-weight: bold; } ``` In the example above ⬆️, the CSS rule will apply to Item 1, Item 3, Item 3.1 and Item 3.3</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/LYdjvRB] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/LYdjvRB">Codepen</a></p>
<ul>
<li><h3 id="heading-nth-last-child-selector">Nth-Last-Child Selector</h3>
<p>  The Nth-Last-Child Selector matches elements based on their position among a group of siblings, counting from the end.</p>
<p>  <strong>The syntax for Nth-Last-Child Selector is:</strong></p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-css">       <span class="hljs-selector-pseudo">:nth-last-child(expression)</span> {
         <span class="hljs-attribute">property</span>: value;
      }
</code></pre>
<p>    Keyword values</p>
<p>    odd : Represents elements whose numeric position in a series of siblings is odd: 1, 3, 5, etc., counting from the end.</p>
<p>    even : Represents elements whose numeric position in a series of siblings is even: 2, 4, 6, etc., counting from the end.</p>
<p>    Functional notation :</p>
<p>    <code>&lt;An+B&gt;</code> Represents elements whose numeric position in a series of siblings matches the pattern An+B, for every positive integer or zero value of n. The index of the first element, counting from the end, is 1. The values A and B must both be <code>&lt;integer&gt;</code>.</p>
<p>    <strong>Example of Last-Child Selector:</strong></p>
<p>    <code>tr:nth-child(odd)</code> or <code>tr:nth-child(2n+1)</code></p>
<p>    Represents the odd rows of an HTML table: 1, 3, 5, etc., counting from the end.</p>
<p>    <code>tr:nth-child(even)</code> or <code>tr:nth-child(2n)</code></p>
<p>    Represents the even rows of an HTML table: 2, 4, 6, etc., counting from the end.</p>
<p>    In the example below ⬇️, there is <code>&lt;li&gt;</code> element. ```html</p>
<ul>
<li><p>Item 1</p>
</li>
<li><p>Item 2</p>
</li>
<li><p>Item 3</p>
</li>
<li><p>Item 4</p>
</li>
<li><p>Item 5</p>
</li>
</ul>
<p>    <code>Styling the above ⬆️ HTML</code></p>
<ul>
<li><p><code>element:</code> css ul li:nth-last-child(2n+1) { color: red; font-weight: bold; } ``` In the example above ⬆️, the CSS rule will apply to Item 4, Item 2, Item 4.3 and Item 4.1</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/YzaxMZB] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/YzaxMZB">Codepen</a></p>
<ul>
<li><h3 id="heading-only-child-selector">Only-Child Selector</h3>
<p>  The Only-Child selector applies a style to an element if it is the only element within a parent.</p>
<p>  <strong>The syntax for Only-Child Selector is:</strong></p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-css">       <span class="hljs-selector-pseudo">:only-child</span> {
         <span class="hljs-attribute">property</span>: value;
      }
</code></pre>
<p>    <strong>Example of Only-Child Selector:</strong></p>
<p>    In the example below ⬇️, there is <code>&lt;li&gt;</code> element. ```html</p>
<ul>
<li><p>Item 1</p>
</li>
<li><p>Item 2</p>
</li>
<li><p>Item 3</p>
<ul>
<li>Item 3.1</li>
</ul>
</li>
<li><p>Item 4</p>
</li>
<li><p>Item 5</p>
</li>
</ul>
<p>    <code>Styling the above ⬆️ HTML</code></p>
<ul>
<li><p><code>element:</code> css ul li:only-child { background: red; color: white; font-weight: bold; } ``` In the example above ⬆️, the CSS rule will apply to Item 3.1 cause is the only child.</p>
<p>  However, here is how it will look on a webpage:</p>
<p>  %[https://codepen.io/KadlagAkash/pen/NWYvmgN] </p>
<p>  View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/NWYvmgN">Codepen</a></p>
<ul>
<li><h3 id="heading-first-of-type-selector">First of Type Selector</h3>
<p>  The First of Type selector represents the first element of its type among a group of sibling elements.</p>
<p>  <strong>The syntax for First of Type Selector is:</strong></p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-css">       <span class="hljs-selector-pseudo">:first-of-type</span> {
         <span class="hljs-attribute">property</span>: value;
      }
</code></pre>
<p>    <strong>Example of First of Type Selector:</strong></p>
<p>    In the example below ⬇️, there is one <code>&lt;h2&gt;</code> and two <code>&lt;p&gt;</code>elements. ```html</p>
<h2 id="heading-heading">Heading</h2>
<p>    Paragraph 1</p>
<p>    Paragraph 2</p>
<p>    ``` Styling the above ⬆️ first paragraph: ```css p:first-of-type { color: red; font-style: italic; } ``` In the example above ⬆️, the CSS rule will apply to 'Paragraph 1' cause is the first of the ```</p>
<p>    ``` type.</p>
<p>    However, here is how it will look on a webpage:</p>
<p>    %[https://codepen.io/KadlagAkash/pen/VwXzNzg] </p>
<p>    View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/VwXzNzg">Codepen</a></p>
<p>    \&gt; <a target="_blank" href="https://stackoverflow.com/questions/24657555/what-is-the-difference-between-first-child-and-first-of-type">Checkout The Difference Between :first-child and :first-of-type</a></p>
<ul>
<li><h3 id="heading-last-of-type-selector">Last of Type Selector</h3>
<p>  The Last of Type selector represents the last element of its type among a group of sibling elements.</p>
<p>  <strong>The syntax for Last of Type Selector is:</strong></p>
</li>
</ul>
<pre><code class="lang-css">       <span class="hljs-selector-pseudo">:last-of-type</span> {
         <span class="hljs-attribute">property</span>: value;
      }
</code></pre>
<p>    <strong>Example of Last of Type Selector:</strong></p>
<p>    In the example below ⬇️ there is one <code>&lt;h2&gt;</code> and two <code>&lt;p&gt;</code> element. ```html</p>
<h2 id="heading-heading-1">Heading</h2>
<p>    Paragraph 1</p>
<p>    Paragraph 2</p>
<p>    ``` Styling the above ⬆️ last paragraph: ```css p:last-of-type { color: blue; font-style: italic; } ``` In the example above ⬆️, the CSS rule will apply to 'Paragraph 2' cause is the last of the ```</p>
<p>    ``` type.</p>
<p>    However, here is how it will look on a webpage:</p>
<p>    %[https://codepen.io/KadlagAkash/pen/JjLyVra] </p>
<p>    View original code in <a target="_blank" href="https://codepen.io/KadlagAkash/pen/JjLyVra">Codepen</a></p>
<ul>
<li><h3 id="heading-nth-of-type-selector">Nth of Type Selector</h3>
<p>  The Nth of the Type selector matches elements based on their position among siblings of the same type (tag name).</p>
<p>  <strong>The syntax for Nth of Type Selector is:</strong></p>
</li>
</ul>
<pre><code class="lang-css">       <span class="hljs-selector-pseudo">:nth-of-type(expression)</span> {
         <span class="hljs-attribute">property</span>: value;
      }
</code></pre>
<p>    <strong>Example of Nth of Type Selector:</strong></p>
<p>    In the example below ⬇️, there are multiple <code>&lt;div&gt;</code> and <code>&lt;p&gt;</code> elements. ```html</p>
<p>    This element isn't counted.</p>
<p>    1st paragraph.</p>
<p>    2nd paragraph.</p>
<p>    This element isn't counted.</p>
<p>    3rd paragraph.</p>
<p>    4th paragraph.</p>
<p>    ``` Styling the above ⬆️ paragraphs: ```css /* Odd paragraphs */ p:nth-of-type(2n+1) { color: skyblue; }</p>
<p>    /* Even paragraphs */ p:nth-of-type(2n) { color: orange; }</p>
<pre><code class="lang-plaintext">
      In the example above ⬆️, the CSS rule will apply skyblue color to 'Paragraph 1' &amp; 'Paragraph 3' and orange color to 'Paragraph 2' &amp; 'Paragraph 4'.

    However, here is how it will look on a webpage:

    %[https://codepen.io/KadlagAkash/pen/abYyxEK]

    View original code in [Codepen](https://codepen.io/KadlagAkash/pen/abYyxEK) 

      &gt; [Checkout The Difference Between :nth-child and :nth-of-type](https://css-tricks.com/the-difference-between-nth-child-and-nth-of-type/) 

    - ### Nth Last of Type Selector
     The Nth Last of Type selector matches elements based on their position among siblings of the same type (tag name), counting from the end.

    **The syntax for Nth Last of Type Selector is:**
    ```css
     :nth-last-of-type(expression) {
       property: value;
    }
</code></pre>
<p>    <strong>Example of Nth Last of Type Selector:</strong></p>
<p>    In the example below ⬇️ there are multiple <code>&lt;div&gt;</code> and <code>&lt;p&gt;</code> elements. ```html</p>
<p>    This element isn't counted.</p>
<p>    1st paragraph.</p>
<p>    2nd paragraph.</p>
<p>    This element isn't counted.</p>
<p>    3rd paragraph.</p>
<p>    4th paragraph.</p>
<p>    ``` Styling the above ⬆️ paragraphs: ```css /* Odd paragraphs */ p:nth-last-of-type(2n+1) { color: skyblue; }</p>
<p>    /* Even paragraphs */ p:nth-last-of-type(2n) { color: orange; }</p>
<pre><code class="lang-plaintext">      In the example above ⬆️, the CSS rule will apply skyblue color to 'Paragraph 4' &amp; 'Paragraph 2' and orange color to 'Paragraph 3' &amp; 'Paragraph 1'.

    However, here is how it will look on a webpage:

    %[https://codepen.io/KadlagAkash/pen/jOzLRzB]

    View original code in [Codepen](https://codepen.io/KadlagAkash/pen/jOzLRzB) 

    - ### Only of the Type Selector
     The Only of Type selector represents an element that has no siblings of the same type.

    **The syntax for Only of Type Selector is:**
    ```css
     :only-of-type {
       property: value;
    }
</code></pre>
<p>    <strong>Example of Only of Type Selector:</strong></p>
<p>    In the example below ⬇️, there are multiple elements in the <code>&lt;main&gt;</code> element. ```html</p>
<p>    I am `div` #1.</p>
<p>    I am the only `p` among my siblings.</p>
<p>    I am `div` #2.</p>
<p>    I am `div` #3. <em>I am the only `i` child.</em> <em>I am `em` #1.</em> <em>I am `em` #2.</em></p>
<p>    ``` Styling the above ⬆️ elements with no siblings of the same type: ```css main :only-of-type { color: red; }</p>
<pre><code class="lang-plaintext">      In the example above ⬆️, the CSS rule will apply red color to ```&lt;p&gt;``` and ```&lt;i&gt;``` elements.

    However, here is how it will look on a webpage:

    %[https://codepen.io/KadlagAkash/pen/ZExJZoa]

    View original code in [Codepen](https://codepen.io/KadlagAkash/pen/ZExJZoa) 

    - ### Not Selector
     The Not selector represents elements that do not match a list of selectors. Since it prevents specific items from being selected, it is known as the negation pseudo-class.

    **The syntax for Only of Type Not Selector is:**
    ```css
     :not(&lt;selector-list&gt;){
       property: value;
    }
</code></pre>
<p>    <strong>Example of Not Selector:</strong></p>
<p>    In the example below ⬇️ there are two <code>&lt;p&gt;</code> elements. ```html</p>
<p>    I am a normal paragraph.</p>
<p>    I am so very fancy paragraph..!</p>
<p>    ``` Styling the above ⬆️ ```</p>
<p>    ``` element with no fancy class: ```css .fancy { background: orange; color: black; text-shadow: 2px 2px 3px red; font-style: italic; }</p>
<p>    p:not(.fancy) { font-style: normal; font-weight: bold; }</p>
<pre><code class="lang-plaintext">      In the example above ⬆️, the CSS rule will not apply font-weight of bold to ```&lt;p&gt;``` element with class="fancy".

    However, here is how it will look on a webpage:

    %[https://codepen.io/KadlagAkash/pen/yLKorxz]

    View original code in [Codepen](https://codepen.io/KadlagAkash/pen/yLKorxz) 

    # In closing
    I hope that you’ve found this tutorial and code examples on CSS Selectors helpful...! If you have any questions or feedback, feel free to leave a comment below.

    If you found this article helpful, please like and share it 💙.

    That's all for today! 😁 You reached the end of the article 😍

    ## Other Resources
    Check out some of these resources for a more in-depth look into CSS selectors :
    - [MDN CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors)
    - [WDS CSS Selectors](https://youtu.be/l1mER1bV0N0)
    - [WDS CSS Pseudo Elements](https://youtu.be/OtBpgtqrjyo)

    ## Want more..?
    I write web development articles on my blog **[@akashkadlag.hashnode.dev](https://akashkadlag.hashnode.dev)**, and also post development-related content on the following platforms:

    - **[Twitter/X](https://twitter.com/yntpdotme)**

    - **[LinkedIn](https://www.linkedin.com/in/yntpdotme)**
</code></pre>
]]></content:encoded></item></channel></rss>