Pradeep Pandey Profile picture
May 13 11 tweets 3 min read
⚡ All You Need to Know About CSS Specificity ⚡

A thread🧵👇🏼
❓ What is Specificity?

📌 If there are two or more conflicting CSS rules that point to the same element, the browser follows some rules to determine which one is most specific and therefore wins out.
🎯 Specificity Hierarchy

⇢ Every CSS selector has its place in the specificity hierarchy.

⇢ Four categories define the specificity level of a selector:

✤ Inline styles

⤷ Example: <h1 style="color: pink;">

✤ IDs ⤷ Example: #navbar
✤ Classes, pseudo-classes, attribute selectors

⤷ Example: .test, :hover, [href]

✤ Elements and pseudo-elements

⤷ Example: h1, :before
So if:

div{background-color: blue;}
div{background-color: red;}

→ What will be the background color of this div?
→ red, right ⚡
but why red?

let me explain why:

⦿ Equal specificity: the latest rule counts.

if the same rule is written twice into the external style sheet, then the lower rule in the style sheet is closer to the element to be styled
That's the reason for the red bg of div
⦿ ID selectors have a higher specificity than attribute selectors

div#a {background-color: green;}
#a {background-color: yellow;}
div[id=a] {background-color: blue;}

→ Here the first rule is more specific than the other two, and will therefore be applied.
⦿ A class selector beats any number of element selectors.

→ a class selector such as .intro beats h1, p, div, etc:

Example:

.intro {background-color: yellow;}
h1 {background-color: red;}
🎯 How to Calculate Specificity?

⇢ Start at 0, add 100 for each ID value,add 10 for each class value (or pseudo-class or attribute selector),add 1 for each element selector or pseudo-element

For example:
A: h1
B: h1#content
C: <h1 id="content" style="color: pink;">Heading</h1>
→ The specificity of A is 1 (one element selector)
→ The specificity of B is 101 (one ID reference + one element selector)
→ The specificity of C is 1000 (inline styling)

Since the third rule (C) has the highest specificity value (1000),this style declaration will be applied
End of the thread. 🧵

If you found this thread useful, please consider:

💛 Liking these tweets

🔁 Retweet the first tweet so others can see it.

👤 Following me ( @Div_pradeep ) for more content.

Thanks for reading.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Pradeep Pandey

Pradeep Pandey Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Div_pradeep

May 12
All About HTML Inputs🎯

A Thread 🧵👇
❓ What are inputs?

📌 Inputs are the fields where users can fill in their info, passwords, email, and much more.

There are a variety of inputs but we can categorize them into 5 groups.
🎯 Input Categories

1. General Inputs
2. Duration Inputs
3. Media Inputs

4. Option Inputs
5. Advance Inputs
Read 10 tweets
May 6
Closures in JavaScript for beginners ⚡⚡

A Thread🧵👇🏻
→ In many languages, you can't use or access the global variables inside the function.

→ But In Javascript, a function has the access to all the variables that have been declared in the higher scope or outside the function.

→ And this feature is called as Closure.
Example:

→ See in the example below I can access the variable name inside the function even it is declared outside the function.

→ So Having access out of the scope(range) is called as Closures.
Read 14 tweets
Apr 26
Strict Mode in JavaScript for beginners ⚡⚡

A Thread🧵👇🏻
🎯What happens before Strict Mode ?

⇨ When we code in javascript there are some errors in that code that we are not able to see and even we don't get an error in the browser for that syntax errors.
⇨ But that syntax error affects later in the coding process.

○ Example :

Num = 5;
console.log(Num);

Above☝️, No Declaration, just Initialized but still Working with this syntax error.
Read 9 tweets
Apr 24
100+ Useful Web Development Resources for Web Developers⚡⚡

A Mega Thread🧵👇🏻 Image
📌 Youtube Channels

⚡FreeCodeCamp
⚡Travesy Media
⚡Kevin Powell
⚡Web dev Simplified
⚡Coder coder
⚡CodeWithHarry
⚡Programming with Mosh
⚡Google Developers
⚡Treehouse
⚡DevEd
📌 Websites for learning

⚡MDN Docs
⚡W3schools
⚡Freecodecamp
⚡Udemy
⚡W3resource
⚡CSS reference
⚡GeeksforGeeks
⚡The Odin Project
⚡JavaScript. info
⚡Css tricks
⚡JavaScript30
Read 13 tweets
Apr 22
Top VS Code Extensions Web Developer Must Know⚡⚡

A Thread🧵👇🏻
1. CodeSnap

⇨ Quickly allows you to create screenshots of your code by simply highlighting the respective snippet within your project. It's that easy!
2. Material Icon Theme

⇨ Get the Material Design icons into your VS Code. Honestly, one of the best icon themes I've ever used, so simple and so much better.
Read 9 tweets
Apr 21
Arrow functions in JavaScript for beginners ⚡⚡

A Thread🧵👇🏻
🎯What Is Arrow Function ?

⇨ Arrow function is one of the features introduced in the ES6 version of JavaScript.

⇨ It allows you to create functions in a cleaner way compared to regular functions.
⇨ Function Syntax:
Read 12 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(