Sumit | Javascript Profile picture
Jul 19 โ€ข 9 tweets โ€ข 3 min read
๐Ÿงต CSS explained: Specificity in CSS Specificity in CSS
In today's thread we'll look at:

โœ” What is specificity
โœ” How is it calculated?
โœ” The best way to use specificity
โœ” Is there a thing as too much specificity
โœ” Some important things to note

Let's begin!
โžฃ So, what is specificity?

For every element, the browser has to decide what CSS rule to apply.

It does so using an algorithm, called specificity.

The browser essentially looks at the stylesheet and based on specificity scores of each element, decides what rule to apply.
โžฃ And how are these specificity scores calculated?

The specificity scores are calculated using the following rules:

โž› for every tag: 1 points
โž› for every class attribute: 10 points
โž› for every id attribute: 100 points
โž› for !important: 1000 points
You can see the css rules and the corresponding specificity scores in the attached image here: specificity rules in CSS
โžฃ So, what's the best way to use specificity?

Well, the best way is to use class names for styles repeating across multiple elements on the website and use ID if you want to target one element specifically.

It is generally a bad idea to have more than one ID usage per page.
โžฃ And is there such thing as too much specificity?

Yes, you can go wild with different selectors and sibling selectors.

But don't

That means don't use things like: '.className #id li.active'

Don't go overboard.

Be reseanably selective!
โžฃ Some important things to note:

โž› The use of '!important' rule overrides everything.

โž› Its specificity score (1000) can only be over-ridden by another '!important' or by matching a 1000 points using other rules.

โž› The universal selector has a specificity score of 0.
That's a wrap!

If you enjoyed this thread:

1. Follow me @sumitsaurabh927 for more of these
2. RT the tweet below to share this thread with your audience

โ€ข โ€ข โ€ข

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

Keep Current with Sumit | Javascript

Sumit | Javascript 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 @sumitsaurabh927

Jul 21
๐Ÿ“Œ X reasons why using Linux makes you a better developer! Image
1. Widespread use:

โฆ You may be surprised to know this but Linux basically powers the computing infrastructure of the entire world.

โฆ From servers to critical cloud infrastructure, from android to screens in Tesla cars, Linux is everywhere Image
2. Designed for developers by developers

โฆ No matter what tools you use, chances are it'll have first class support on Linux, unless of course, if you're using any proprietary technology.

โฆ It has built with development in mind and has tools like git built-in.
Read 15 tweets
Jul 20
Fu*k sleep, I'm reinstalling Linux again!
.
.
.
.
.
.
.
Context and updates ๐Ÿ‘‡
Update 1: Taking backup! A laptop, External disk and...
Read 8 tweets
Jul 13
๐Ÿ“Œ Learn web development by playing these games!

These games will improve your:

โ— Flexbox skills

โ— Visualization skills

โ— CSS selector skills

โ— Javascript skills

โ— HTML, CSS, Javascript - all in one!

So, buckle up and start playing these to enhance your skills! Image
โžฃ Flexbox Froggy:

This was the first 'web dev' game I had played and I found it so addictive that I finished it in one go.

As is evident from the name, this puzzle game helps you master your flexbox skills.

The initial levels are simple but the last few ones are challenging! Image
โžฃ Pixactly:

Again, think of the name. It is made up of two words - pixels and exactly.

And that's what you have to do in this game.

You'll be given a resolution and you have to draw a rectangle.

The closer you can get to the dimension, the better! Image
Read 6 tweets
Jul 12
๐Ÿ“Œ 11 tweets to get you out of tutorial hell! Image
First things first, what exactly is a tutorial hell?

โžฃ Well, when folks begin to learn to code, they typically start with some sort of tutorial, in which there's nothing wrong.

โžฃ But when they try to build stuff on their own, they notice some gaps in their knowledge.
โžฃ Now, to overcome these gaps, they jump on to another tutorial by some other instructor.

โžฃ This gives them a false sense of achievement.

โžฃ Because in their mind they ARE STUDYING.

โžฃ And because things work if they copy code, they think 'Wow, I understand it.
Read 13 tweets
Jul 11
๐Ÿ“Œ Top 5 websites that have improved my typing speed!
When I began my odyssey into the world of computers, I typed miserably.

I didn't know which key was where.

Heck, I didn't even know that there was a 'certain' way (It is called touch typing) I should have typed.
But typing correctly not only is faster, it also reduces the chances of you developing injuries in your fingers.

So fasten your seat belts as I take you on a journey of 5 websites that have helped me immensely!
Read 10 tweets
Jul 10
๐Ÿ“Œ Top 10 movies every coder must watch!
1. Chappie (2015):

I watched this movie as a kid and still remember it.

It was the first robot movie I'd watched that really fascinated me and made it look 'cool' in the mind of a teenage me.

I've some fond memories of this film and you won't be disappointed!
2. Iron man (2008):

This was the first 'tech' movie I had seen and it blew my mind away.

Everything in this film is just super awesome.

Tech, checked!

Coolness quotient, checked!

Sassism, checked!

On top of everything, there's OFC, Jarvis!

Must watch for every techy!!!
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!

:(