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

A thread🧵👇🏼 Image
❓ 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

Apr 3
7 Useful Websites to find Free Illustrations ⚡⚡

A Thread 🧵👇🏻
1. undraw.co/illustrations

Browse through to find the images that fit your needs and click to download.
2. openpeeps.com

Open Peeps is a hand-drawn illustration library to create scenes of people. You can use them in product illustration, marketing, comics, and product states.
Read 9 tweets
Apr 2
Top 8 Free Useful Generators for Web Developers ⚡️⚡️

A Thread🧵👇
1. cubic-bezier.com

Cubic-bezier is a tool to Preview & compare cubic-bezier easings as you customize &, and it lets you copy it.
2. css3generator.com

It comes with many useful generator tools to demonstrate many CSS properties in a quick visual way.
Read 10 tweets
Mar 28
Top Free Cheatsheet list for Web developers⚡

A thread🧵👇
1. htmlcheatsheet.com

Online interactive HTML Cheat Sheet contains useful code examples and web developer tools, markup generators, and more
2. cssreference.io

CSS Reference is a free visual guide to CSS. It features the most popular properties and explains them with illustrated and animated examples.
Read 7 tweets
Mar 15
Master CSS Pseudo-elements🎯

A Thread 🧵👇
❓What exactly is a pseudo-element?

📌 A CSS pseudo-element is used to style specified parts of an element.

For example, it can be used to:

🔳 Style the first letter, or line, of an element.

🔳 Insert content before, or after, the content of an element.
📌 Presently, There are some pseudo-elements that are commonly used , and some experimental ones.

Below I have given a detailed explanation👇
Read 14 tweets
Mar 14
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
Mar 13
Do you know about CSS cursor Property in CSS ?

What is the use of Cursor Property?

Let's understand👇

#100DaysOfCode
#webdevelopment
📌 The cursor property specifies the mouse cursor to be displayed when pointing over an element.

📌 They support multiple conditions depending on what the website interface state is at the current moment.
➡️ For example, you might need a loading state cursor while loading items.

📌 This tells the users that something is in progress in the background, and they need to wait until the fetching finishes.
Read 9 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!

:(