Ashish Kumar Profile picture
Jan 26 β€’ 17 tweets β€’ 4 min read
Confused about why your CSS property is not being applied?

CSS might be confusing.

πŸ˜• πŸ˜• πŸ˜•

Let's make it easy by understanding CSS Cascade and inheritance in this CSS Mega Thread. 🧡

πŸ˜ƒ πŸ˜ƒ πŸ˜ƒ
πŸ‘‰ Conflicting rules: We need to understand how cascading works in CSS. There might be times that your CSS rule is not being applied. It's mostly because you might have created two rules for the same element.

Example:
πŸ‘‰ The cascade, and the closely-related concept of specificity, are mechanisms that control which rule applies when there is such a conflict.
πŸ‘‰ Specificity: This is how the browser decides which rule applies if multiple rules have different selectors, but could still apply to the same element.
πŸ‘‰ An element selector is less specific as its selects all the elements and so will get a lower specificity.

A class selector is more specific as it selects only the elements on a page that have a specific class attribute value β€” so will get a higher score
πŸ‘‰ Inheritance: Inheritance generally means that some properties of the parent are also applied to the child element.

Properties like Font-Family & color etc. are examples of this.
πŸ‘‰ How to control inheritance?

CSS Provides 4 Properties that can be used to control inheritance. These are universal and every CSS property accepts these values.

➑ inherit
➑ initial
➑ unset
➑ revert
πŸ‘‰ inherit: It sets the property applied to the parent to a selected element.

In the example below the <h1> has color property inherited from the parent div.
πŸ‘‰ initial: Sets the value of a selected element to its initial value i.e default value.

In the example below the <em> tag has the property initial and its defaults to black in color.
πŸ‘‰ unset: Resets the property to its natural value, which means that if the property is naturally inherited it acts like inherit, otherwise it acts like the initial.
πŸ‘‰ revert: Similar to unset most of the time, however, will revert the property to the browser's default styling rather than the defaults applied to that property.
πŸ‘‰ Understanding Cascade and Specificity:

Three factors to consider, are listed here in increasing order of importance.

➑ Source order
➑ Specificity
➑ Importance
πŸ‘‰ Source order: As we already saw above If you have more than one rule, which has exactly the same weight, then the one that comes last in the CSS will win.

Example:
πŸ‘‰ Specificity: As we know by the source order the property which comes later will be applied but in some cases, we do see the first is applied it is because the first one has higher specificity.

The example shows how class selector has more specificity than element selector.
πŸ‘‰ Importance: is denoted by !important. a special piece of CSS that you can use to overrule all of the above calculations.

Used to make a particular property and value the most specific thing, thus overriding the normal rules of the cascade.

Example:
TLDR;
CSS properties depend on cascading which means the property which comes last will be applied until it has been overruled by higher specificity. Some properties are inherited from parent to child which can be altered with properties.
And !important overrides rule of cascade
Hey Everyone πŸ‘‹ I am Ashish.

I make your web development journey easy.
I share daily content on Web development tips, threads, and dev tools.

If you find this helpful then.
❀️ Like it
πŸ” Retweet the first tweet.
πŸ‘‰ Follow me

Thank you, friends. Keep Learning.

β€’ β€’ β€’

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

Keep Current with Ashish Kumar

Ashish Kumar 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 @Ashish_feels

Jan 19
10 Generator tools for Developers & Designers, You Won’t Believe Exist. 🀯 🀯 🀯

Save 10+ hours of researching/Coding/Designing

A Thread 🧡 πŸ‘‡
πŸš€ cssgrid-generator.netlify.app

A CSS Grid Generator tool, Generates CSS grid easily.
πŸš€ markodenic.com/tools/buttons-…

Amazing collection of Beautiful Pprebuilt CSS buttons.
by @denicmarko
Read 12 tweets
Jan 17
5 Resources to learn Web Development for Beginners.

99.8 % of the web developers don't know about all of them.

A super useful Thread 🧡 for beginners
πŸ‘‰ learn.shayhowe.com

One of the Best Ways to learn about HTML and CSS Awesome guides do check it out.
πŸ‘‰ theodinproject.com

free full-stack curriculum, supported by a passionate open source community
Read 7 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

Too expensive? 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!

:(