Ashish Kumar Profile picture
Jan 26, 2022 โ€ข 17 tweets โ€ข 4 min read โ€ข Read on X
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 @afkashish

Feb 27, 2022
6 Youtube Playlists that will make you a JavaScript Developer for Free. ๐Ÿ’ฏ

Learn Now at your own pace & comfort.
A Thread ๐Ÿงต ๐Ÿ‘‡
๐Ÿ‘‰ Namaste JavaScript by Akshay Saini:
@akshaymarch7

youtube.com/playlist?list=โ€ฆ
๐Ÿ‘‰ JavaScript Playlist by Dave Gray:
@yesdavidgray

youtube.com/playlist?list=โ€ฆ
Read 8 tweets
Feb 19, 2022
7 Free Javascript Books/Guides that will help you boost your JavaScript Knowledge. ๐Ÿ’ฏ

A Thread ๐Ÿงต ๐Ÿ‘‡
๐Ÿ‘‰ Eloquent JavaScript: eloquentjavascript.net

Amazing Book for beginners.
๐Ÿ‘‰ JavaScript The Right Way: jstherightway.org

Basics to Design Patterns all covered.
Read 9 tweets
Feb 15, 2022
12 Github Repos that will make you a better Javascript Developer. ๐Ÿ’ฏ

A Thread ๐Ÿงต ๐Ÿ‘‡
Read 14 tweets
Feb 10, 2022
โšก Learn CSS selectors in one thread โšก

The only thread you need to learn about CSS Selectors.

A Mega Thread ๐Ÿงต
๐Ÿ‘‰ CSS, selectors are used to target the HTML elements on our web pages that we want to style. There are a wide variety of CSS selectors available, allowing for fine-grained precision when selecting elements to style.
๐Ÿ‘‰ A selector is the first part of a CSS Rule. Typically a pattern or term decides which HTML element it needs to select. The Elements that are selected are called subjects of the selector.
Read 20 tweets
Feb 5, 2022
๐Ÿš€ Crack your next Job Interview with Github.

๐Ÿ‘‰ Collection of Github repositories that will help you crack your next interview.

A Thread ๐Ÿงต ๐Ÿ‘‡
Read 24 tweets
Feb 4, 2022
๐Ÿš€ Learn Javascript Objects in One Thread ๐Ÿš€

Still, confused about Javascript Objects?

๐Ÿ˜ณ ๐Ÿ˜ณ ๐Ÿ˜ณ

Here is a Thread that will help you learn Objects in Javascript in an easy way.

๐Ÿ˜Ž ๐Ÿ˜Ž ๐Ÿ˜Ž

A thread to Bookmark ๐Ÿงต
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!

:(