Continuing our journey from the basics of CSS, we'll today learn about:
- What is cascading?
- What happens when CSS rules conflict with each other?
- How to resolve conflicts?
If you wanna take a look at yesterday's thread, you can check it out here:
- What is cascading?
- What happens when CSS rules conflict with each other?
- How to resolve conflicts?
If you wanna take a look at yesterday's thread, you can check it out here:
But first, let's take a look at what cascade means.
See, in web dev, we've 3 ways to apply CSS rules to HTML. They are:
1. Internal CSS - writing CSS in 'style' tag in HTML
2. Inline CSS - writing CSS as attributes of HTML tags.
3. External CSS - writing CSS in an external file
See, in web dev, we've 3 ways to apply CSS rules to HTML. They are:
1. Internal CSS - writing CSS in 'style' tag in HTML
2. Inline CSS - writing CSS as attributes of HTML tags.
3. External CSS - writing CSS in an external file
So, one HTML element can have multiple CSS rules written for it. This causes cascading of CSS rules.
Well, that's easy. Just use only one way to write CSS and avoid it altogether.
Hmmm, it looks plausible but it doesn't quite work that way...๐
Well, that's easy. Just use only one way to write CSS and avoid it altogether.
Hmmm, it looks plausible but it doesn't quite work that way...๐
You see, the hierarchy of CSS rules is as follows:
- Default CSS (by the browser)
- User-defined stylesheet
- External CSS
- Page-specific CSS
- Inline CSS
And even if we were to write CSS using just one way, we can still write multiple CSS declarations for one HTML element.
- Default CSS (by the browser)
- User-defined stylesheet
- External CSS
- Page-specific CSS
- Inline CSS
And even if we were to write CSS using just one way, we can still write multiple CSS declarations for one HTML element.
And when we have a situation where there are multiple CSS rules for one HTML element, which rule is going to be applied to it, is determined by the cascade.
There are three factors that determine this:
1. Specificity
2. Inheritance
3. Order of appearance
Let's look at them..๐
There are three factors that determine this:
1. Specificity
2. Inheritance
3. Order of appearance
Let's look at them..๐
Lastly, note that although we can write CSS rules in multiple ways as specified above, writing it in an external file is the most preferred way of writing CSS.
So, unless you have specific reasons not to do that, always write CSS rules in an external file.
So, unless you have specific reasons not to do that, always write CSS rules in an external file.
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 and show me some love! ๐งก๐งก๐งก
If you enjoyed this thread:
1. Follow me @sumitsaurabh927 for more of these
2. RT the tweet below to share this thread and show me some love! ๐งก๐งก๐งก
Loading suggestions...