i

Learn HTML and CSS in 10 Days

Build Proficient Selectors

If the CSS selectors are not maintained, then there are chances that they will get out of control. They can become too location-specific as well as too long.

The more the prequalifies a selector has, the higher the specificity it contains. The higher the specificity, the more chances is there that a selector is going to break the CSS cascade. It will lead to undesirable issues.

Keep in mind not to use IDs inside our selectors to keep the specificity of our selectors low. IDs rapidly uplifts the specificity of a selector, overly specific, and generally breaks the cascade inside the CSS file. The cons far exceed the pros with IDs, and we are astute to maintain a strategic distance from them.

Let us utilize primarily and shorter direct selectors.

Bad Code

#aside #featured ul.news li a { ... }

#aside #featured ul.news li a em.special { ... }

Good Code

.news a { ... }

.news .special { ... }