<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Falaye Promise</title>
    <description>The latest articles on DEV Community by Falaye Promise (@promiseanuoluwa).</description>
    <link>https://dev.to/promiseanuoluwa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1403556%2Ffda5e91a-9974-4291-983d-b0345f56fc4e.jpeg</url>
      <title>DEV Community: Falaye Promise</title>
      <link>https://dev.to/promiseanuoluwa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/promiseanuoluwa"/>
    <language>en</language>
    <item>
      <title>The Document Object Model (DOM)</title>
      <dc:creator>Falaye Promise</dc:creator>
      <pubDate>Mon, 06 May 2024 22:52:17 +0000</pubDate>
      <link>https://dev.to/promiseanuoluwa/the-document-object-model-dom-2gi4</link>
      <guid>https://dev.to/promiseanuoluwa/the-document-object-model-dom-2gi4</guid>
      <description>&lt;p&gt;Hey there! Let's jump into the world of the Document Object Model, or DOM for short. If you're already familiar with HTML, CSS, and JavaScript, that's great! But even if you're new to these, we'll cover the basics to get you started.&lt;/p&gt;

&lt;p&gt;Imagine a website as a house. HTML is the blueprint, defining the structure of the rooms, doors, and windows. CSS is the interior decorator, making everything look snazzy with colors, fonts, and layouts. Finally, JavaScript is like the electrician and plumber, adding interactivity – like turning on lights (changing content) when you click a button.HTML, CSS and JS are the building blocks of the web.&lt;/p&gt;

&lt;h3&gt;
  
  
  Javascript and the DOM
&lt;/h3&gt;

&lt;p&gt;So, you may ask, how does JavaScript make a webpage interactive? This is where the DOM comes in. JavaScript needs a way to understand the content of the webpage, which has been defined by HTML. The DOM acts as a bridge, creating a tree-like structure of all the elements on the page and making it accessible to JavaScript. &lt;/p&gt;

&lt;p&gt;The DOM structure is hierarchical, like an upside-down family tree. The entire document is the root node, with branches for different elements. The cool thing is, most browsers have built-in DOM viewers (like the Elements tab in Chrome DevTools) to help you as the developer to visualize this structure.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The DOM can be navigated with different programming languages but of all javascript is the most common.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What can you do with the DOM?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Change content: Update text, add new elements, or remove existing ones.&lt;/li&gt;
&lt;li&gt;Style manipulation: Control the look and feel of the page by changing fonts, colors, and backgrounds.&lt;/li&gt;
&lt;li&gt;Respond to user interaction: Make elements react to clicks, hovers, or other user actions.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Structure of the DOM
&lt;/h2&gt;

&lt;p&gt;We mentioned the DOM tree – a visual representation of the webpage's elements. Each element in the DOM is like an object with properties and methods that let you access and manipulate its content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nodes: The Building Blocks of the DOM Tree&lt;/strong&gt;&lt;br&gt;
Every element on the webpage is a node in the DOM tree. The document itself is also the root node. Nodes aren't limited to elements, though. They can also be text content or attributes within elements.&lt;/p&gt;

&lt;p&gt;Nodes come with built-in properties you can use to navigate and access other elements in the DOM. Here are a few:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;u&gt;node.childNodes&lt;/u&gt; - returns a nodelist containing all the child nodes of the selected node&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;node.firstChild&lt;/u&gt; - returns the first child of the selected node&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;node.lastChild&lt;/u&gt; - returns the last child of the selected node&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;node.parentNode&lt;/u&gt; - returns the parent node of the specified node&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;node.nextSibling&lt;/u&gt; - returns the node that comes directly after the specified node in their parent nodelist&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;node.previousSibling&lt;/u&gt; - returns the node that comes directly before the specified node in their parent nodelist&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;node.hasChildNodes&lt;/u&gt; - a method. Returns true or false indicating whether the selected node has any child nodes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Document Object: The Entry Point&lt;/strong&gt;&lt;br&gt;
Remember the document being the root node? This "document object" also acts as the entry point for accessing other nodes in the DOM tree. It has its own methods and properties for manipulating the webpage content:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;u&gt;querySelectorAll&lt;/u&gt; - Grabs all elements matching a CSS selector. The selector could be  class, ID, tag name, or even a combination of these.It returns a NodeList containing all the elements in the document that match that selector. Very &lt;strong&gt;powerful&lt;/strong&gt;! because it can query class, id or tag. &lt;/li&gt;
&lt;li&gt;
&lt;u&gt;createElement&lt;/u&gt; - creates a new HTML element of the specified type (e.g., "div", "p", "h1").&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;getElementById&lt;/u&gt; - Gets an element by its unique ID. It's a quick way to target a single element with a known ID. Very &lt;strong&gt;fast&lt;/strong&gt;!&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;getElementsByTagName&lt;/u&gt; - Gets all elements with a specific tag name. It returns a NodeList containing all the elements in the document with that specific tag name.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;appendChild&lt;/u&gt; - Adds a new child element to the end of another element. &lt;/li&gt;
&lt;li&gt;
&lt;u&gt;innerHTML&lt;/u&gt;- Gets all the content inside an element. &lt;/li&gt;
&lt;li&gt;
&lt;u&gt;addEventListener &lt;/u&gt;- Makes an element listen for events and run code when they happen. The listener function is triggered when a specific event like a click, mouseover, or keypress occurs on that element. &lt;/li&gt;
&lt;li&gt;
&lt;u&gt;replaceChild&lt;/u&gt;- Takes two nodes as input. Replaces an existing child node of a parent node with a new child node.&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;insertBefore&lt;/u&gt; - Takes two nodes and a reference node as input. Inserts a new child node before a specified reference node within the same parent&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;setAttribute&lt;/u&gt; - Changes or sets the value of an element's attribute. This method sets the value of a specified attribute on an element. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you've got a foundational understanding of the DOM! We explored its role in bridging JavaScript and HTML, how it structures the webpage content, and how you can use it to manipulate the webpage dynamically. With this knowledge, you can start building more interactive and engaging web experiences!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Decoding CSS: Mastering Cascade, Selectors, and Specificity for Smarter Styling.</title>
      <dc:creator>Falaye Promise</dc:creator>
      <pubDate>Thu, 18 Apr 2024 22:50:52 +0000</pubDate>
      <link>https://dev.to/promiseanuoluwa/decoding-css-mastering-cascade-selectors-and-specificity-for-smarter-styling-4c78</link>
      <guid>https://dev.to/promiseanuoluwa/decoding-css-mastering-cascade-selectors-and-specificity-for-smarter-styling-4c78</guid>
      <description>&lt;p&gt;In the ever-evolving world of web development, mastering CSS (Cascading Style Sheets) is crucial for creating visually appealing and technically sound websites. At the heart of CSS lie three fundamental concepts: the cascade, selectors, and specificity, and understanding these concepts is key to writing efficient and effective style sheets. This article delves deep into these concepts, explaining each one with clarity and providing examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS SYNTAX
&lt;/h2&gt;

&lt;p&gt;Generally, a syntax is a set of rules that define what the various combinations of symbols mean. In computer science, a syntax is essentially a set of keywords and characters that a computer can read, interpret, and convert into tasks that it knows it needs to do.&lt;br&gt;
They are like recipes which have to be followed to get the desired result. If a particular step in the recipe is missed, the meal wouldn’t turn out as it should, this is the exact same thing when an incorrect syntax is used in CSS and even programming languages in general.&lt;/p&gt;

&lt;p&gt;A computer program is a set of instructions written in a programming language that tells the computer what to do. Like humans, computers cannot get a sense of what instructions you are passing across if the instruction is not given in its entirety. The closest thing you can get to this are Integrated Development Environments that can point out where an error is from, but even with this, you still have to write the correct syntax. A coding syntax must be exact and specific if not, there will be errors.&lt;/p&gt;

&lt;p&gt;To understand the CSS syntax, let us learn about CSS rulesets first. The structure of CSS rule set is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P {
Color:red
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above is known as a ruleset. Where &lt;code&gt;P&lt;/code&gt; is the selector, &lt;code&gt;color&lt;/code&gt; is the rule property and &lt;code&gt;red&lt;/code&gt; the property value. &lt;code&gt;Color:red&lt;/code&gt; is referred to as a declaration.&lt;br&gt;
CSS rulesets are the fundamental building block of stylesheets. This means a stylesheet contains lots and lots of rulesets.&lt;/p&gt;
&lt;h3&gt;
  
  
  The syntax of a CSS rule set
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Each rule set must be wrapped in curly braces.&lt;/li&gt;
&lt;li&gt;A colon should be used to separate a property from its value.&lt;/li&gt;
&lt;li&gt;A semicolon is used to separate one property declaration from the next.&lt;/li&gt;
&lt;li&gt;Multiple selectors are separated by commas.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  SELECTORS
&lt;/h2&gt;

&lt;p&gt;CSS selectors are patterns used to select and style HTML elements. In the ruleset example given earlier, it is seen that CSS rules are usually added to selectors to specify the styling of the &lt;em&gt;selected&lt;/em&gt; element. CSS selectors go hand in hand with &lt;strong&gt;CSS combinators&lt;/strong&gt; which are symbols that specify the relationship between selectors. &lt;/p&gt;

&lt;p&gt;CSS selectors allow elements to be targeted based on their type, class, id, attributes among others WHILE combinators allow elements to be targeted based on their position in relation to other ones. CSS combinators gives more precision in selecting an element(s). There are different types of selectors and combinators that have been made available by CSS.&lt;/p&gt;
&lt;h3&gt;
  
  
  Types of selectors
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Element or type selector&lt;/u&gt; - target HTML elements by their type. &lt;br&gt;
In this example, the h1 element selector is used in the CSS rule. This rule will style all &lt;code&gt;h1&lt;/code&gt; elements on the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Element Selector&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;Targets HTML elements by their element type (tag name)&amp;lt;/p&amp;gt;
&amp;lt;h1&amp;gt;Id Selector&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1 {
    color: greenyellow;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7z61objftl2mcxogspo1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7z61objftl2mcxogspo1.png" alt="Image description" width="618" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Id selector&lt;/u&gt; - Targets a unique HTML element by its assigned ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Element Selector&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;Targets HTML elements by their element type (tag name)&amp;lt;/p&amp;gt;

&amp;lt;h1&amp;gt;Id Selector&amp;lt;/h1&amp;gt;
&amp;lt;p id="text"&amp;gt;Targets HTML elements by their Id&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;This paragraph won't be affected by the ID selector&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1 {
    color: greenyellow;
}
#text {
    color: red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8ixwg0ajbnzuy0nhzfsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8ixwg0ajbnzuy0nhzfsu.png" alt="Image description" width="670" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Class selector&lt;/u&gt; - Targets HTML elements by their assigned class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Class Selector&amp;lt;/h1&amp;gt;
&amp;lt;p class="blue"&amp;gt;targets HTML elements by their class&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;More than one element can have the same class&amp;lt;/p&amp;gt;
&amp;lt;p class="blue"&amp;gt;Classes are used to group elements to which same style wants to be applied&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1 {
    color: greenyellow;
}
.blue {
    color: blue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjf0tc8gfqukg5e47fqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjf0tc8gfqukg5e47fqg.png" alt="Image description" width="641" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Attribute Selector&lt;/u&gt; - Targets HTML elements based on the presence of a specific attribute and optionally its value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Attribute Selector&amp;lt;/h1&amp;gt;
&amp;lt;form action=""&amp;gt;
    &amp;lt;label for="name"&amp;gt;Name:&amp;lt;/label&amp;gt;
    &amp;lt;input type="text" name="" id=""&amp;gt;
    &amp;lt;br&amp;gt;
    &amp;lt;br&amp;gt;
    &amp;lt;label for="email"&amp;gt;Email:&amp;lt;/label&amp;gt;
    &amp;lt;input type="email" id=""&amp;gt;
    &amp;lt;br&amp;gt;
    &amp;lt;br&amp;gt;
    &amp;lt;label for="password"&amp;gt;Password:&amp;lt;/label&amp;gt;
    &amp;lt;input type="password" id="password"&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1 {
    color: greenyellow;
}
input[type="text"] {
    background-color: yellow;
  }
input[type='password'] {
    background-color: palevioletred;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuuaezqx3n4uj2iptdkj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuuaezqx3n4uj2iptdkj.png" alt="Image description" width="509" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Pseudo-class and pseudo-element selectors&lt;/u&gt; -Pseudo-class selectors target elements based on their state or user interaction. Pseudo-Elements selectors target specific parts of an element and allow you to style them independently. &lt;/p&gt;

&lt;p&gt;In the example below, the &lt;code&gt;:hover&lt;/code&gt; pseudo-class is used to style an element when the user hovers over it with the mouse. The &lt;code&gt;::first-line&lt;/code&gt; pseudo-element targets the first line of text within an element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Pseudo-class Selector&amp;lt;/h1&amp;gt;
    &amp;lt;a href="#"&amp;gt;Hover on this link to see the color change&amp;lt;/a&amp;gt;
    &amp;lt;h1&amp;gt;Pseudo-Element Selector&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. 
       Est suscipit sequi vitae illo corrupti aspernatur
       necessitatibus, ex dolorem aliquam itaque ad provident 
       minima ea eius tenetur dicta laudantium omnis. Recusandae? 
       Lorem ipsum dolor sit amet consectetur adipisicing elit. 
       Voluptatibus, numquam beatae architecto nostrum voluptas 
       dolore sunt blanditiis deleniti temporibus, saepe dolores 
       nam quaerat cumque? Odit officia iste aperiam obcaecati 
       sunt?
    &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p::first-line {
    color: #ff0000;
    text-transform: uppercase;
  }

a:hover {
    color: #FF00FF;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7p692tywh4t5n2r15l0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7p692tywh4t5n2r15l0.png" alt="Image description" width="800" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Universal selector&lt;/u&gt; - target all HTML elements on a page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Universal Selector&amp;lt;/h1&amp;gt;
&amp;lt;div&amp;gt;
The universal selector targets all HTML elements on the page
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. Est suscipit sequi vitae illo corrupti aspernatur &amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;necessitatibus, ex dolorem aliquam itaque ad provident minima ea eius tenetur dicta laudantium omnis. Recusandae? &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
    color:crimson;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsrrrkg3no9uz6zzc05km.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsrrrkg3no9uz6zzc05km.png" alt="Image description" width="800" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of combinators
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;u&gt;Descendant combinator&lt;/u&gt; - denoted by a whitespace “ ”&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Child combinator&lt;/u&gt; - denoted by the greater than sign &lt;strong&gt;&amp;gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;Adjacent sibling combinator&lt;/u&gt; - denoted by the addition sign &lt;strong&gt;+&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;u&gt;General sibling combinator&lt;/u&gt; - denoted by the tilde symbol &lt;strong&gt;~&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  CASCADE AND SPECIFICITY
&lt;/h2&gt;

&lt;p&gt;Sometimes when working on a project, directly or indirectly it is possible that you set two or more declarations with different values for the same element. This is known as &lt;strong&gt;conflicting rules&lt;/strong&gt;. And more often than not, it is the value you do not want rendered that gets rendered(&lt;em&gt;a typical case of CSS cssing&lt;/em&gt;). The understanding of specificity and cascading is required in this context as they are both the mechanisms controlling which declaration is “preferentially” picked over the other.&lt;/p&gt;

&lt;p&gt;CSS specificity and cascade determines how styling is applied to HTML and how styling conflicts are resolved. Rule sets are said to be conflicting if and &lt;strong&gt;ONLY IF&lt;/strong&gt; the value of the rules are different. For example if color is set to red in two different rulesets for a single element, they are not conflicting.&lt;/p&gt;

&lt;p&gt;Cascading depends on three things, in the order of increasing importance, they are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Source order&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This means that when there is more than one ruleset declaration with the same weight targeted at an element, the one nearer to the element is applied to it. It is &lt;u&gt;important&lt;/u&gt; to note that source order only applies when the specificity or weight of both rules is the same.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Specificity&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This moves a step further than source order by applying to ruleset declarations with different weights. Ideally, different selectors have different specificity scores. A value, usually a number, is assigned to each type of selector by the browser. It is these values which when summed up gives the specificity score of a ruleset and determines which one will be picked over the other. &lt;/p&gt;

&lt;p&gt;Below are the different types of selectors and their specificity scores:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Universal selectors and combinators = 0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type(Element) ad pseudo-type selector = 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Class, pseudo-class and attribute selector = 10&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Id selector = 100&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inline styling = 1,000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;!important flag = 10,000&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The specificity score is determined based on the number of elements that each selector can point to on a page. For example the universal selector points to all elements on the page and inline styling just points to a particular element. Even without the numbers, you have an idea which is more specific than the other.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Each selector has its specificity level that cannot be overwritten by another selector with low specificity. So, even if you try using 200 class selectors for an element and it has one id selector, the id selector will be picked over the 200 class selectors.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Importance&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;strong&gt;&lt;em&gt;!important&lt;/em&gt;&lt;/strong&gt; is a flag which when added to a declaration, will override any other selector with a declaration that is conflicting no matter the type. Its specificity score is 10,000. &lt;/p&gt;

&lt;p&gt;In conclusion, it is very evident now that by understanding and applying the right selectors and rules, developers can control the styling of web elements with precision, ensuring that the desired styles are applied in the right context. CSS may initially seem daunting, but with enough practice, mastering its core concepts is possible. &lt;/p&gt;

</description>
      <category>css</category>
      <category>cssselectors</category>
      <category>specificity</category>
      <category>cascade</category>
    </item>
  </channel>
</rss>
