Post by account_disabled on Nov 29, 2023 21:52:34 GMT -6
When we write CSS in a large website project with many CSS Selectors, the problem that we often encounter is the CSS that we write and then refuses to work because it is overwritten by another Selector. We have to add !important to force it to work . Inserting !important can help solve problems quickly. But the more we write code, we find that adding !important will cause problems with other elements all the time and make the code difficult to maintain in the long run. Especially with big projects, we shouldn't use !important at all. Recommended article: CSS Guideline β Techniques for writing professional CSS.
What does this article have? Show What is CSS Specificity? Once you know, you'll stop Phone Number List using !important. CSS Specificity is the concept of choosing a CSS Selector with the most "power" to use with elements on the website. (Let's use this word already. It looks like a card with some kind of combat power. Whoever has more power wins 55) CSS language is like other programming languages ββin which code is read from top to bottom. This means that if you write 2 duplicate CSS Selectors, the bottom one will be used because it is newer.
But what's special about CSS is that different selectors each have different "power values" and when the "power values" are different, the order in which the code is written will not have an immediate effect. If you notice in point 1, you will see that if we write Inline CSS (write CSS into style) it will have higher power than everything else (1000 points). Therefore, when we want to enforce any CSS, we can write it as Inline CSS, but it is recommended. Just take the time to test it. The actual website should not have CSS in the HTML because it will make the HTML file heavy and load slowly, which is bad for SEO. For !important that is not in points 1 - 4 above, if you add it in, it will force that CSS immediately.
What does this article have? Show What is CSS Specificity? Once you know, you'll stop Phone Number List using !important. CSS Specificity is the concept of choosing a CSS Selector with the most "power" to use with elements on the website. (Let's use this word already. It looks like a card with some kind of combat power. Whoever has more power wins 55) CSS language is like other programming languages ββin which code is read from top to bottom. This means that if you write 2 duplicate CSS Selectors, the bottom one will be used because it is newer.
But what's special about CSS is that different selectors each have different "power values" and when the "power values" are different, the order in which the code is written will not have an immediate effect. If you notice in point 1, you will see that if we write Inline CSS (write CSS into style) it will have higher power than everything else (1000 points). Therefore, when we want to enforce any CSS, we can write it as Inline CSS, but it is recommended. Just take the time to test it. The actual website should not have CSS in the HTML because it will make the HTML file heavy and load slowly, which is bad for SEO. For !important that is not in points 1 - 4 above, if you add it in, it will force that CSS immediately.