"CSS 'has' Not: Mastering Selectors & Pseudo-classes"

In the world of web development, it's not uncommon to come across CSS properties that you might think should exist, but surprisingly, they don't. This article explores some of the most notable "CSS has not" scenarios, providing insights into why these properties don't exist and offering alternative solutions.

Understanding CSS Omissions

CSS, while powerful, is not without its gaps. Some properties that might seem intuitive or useful are absent due to various reasons. Understanding these reasons can help us appreciate the thought process behind CSS design and make more informed decisions when coding.

Why Some CSS Properties Don't Exist

  • Browser Compatibility: CSS properties that aren't widely supported across browsers may be omitted to prevent fragmentation and ensure consistent rendering.
  • Performance: Some properties might be resource-intensive to implement, leading to slower rendering times. Omitting them helps maintain performance.
  • Simplicity and Predictability: CSS is designed to be simple and predictable. Omitting certain properties helps maintain this simplicity and prevents unexpected behavior.

Notable "CSS Has Not" Scenarios

1. display: sticky

While CSS offers position: sticky, which is similar, it doesn't have a dedicated display: sticky value. The latter would make elements stick to their position relative to their container, regardless of scrolling. However, this behavior is already covered by position: sticky.

How To Fix Custom CSS Not Working
How To Fix Custom CSS Not Working

2. text-align: justify

CSS doesn't have a text-align: justify property because it's complex to implement and can lead to inconsistent results across browsers. Instead, consider using a combination of text-align: left or right with a flexible container width to achieve a similar effect.

3. animation: pause

There's no animation: pause property because pausing animations can be achieved using the animation-play-state property with values paused or running. For example, animation-play-state: paused; will pause an animation.

Alternatives and Workarounds

When faced with a "CSS has not" scenario, remember that there's often a workaround. This could be using a combination of existing properties, a preprocessor like Sass or Less, or even a JavaScript library like GSAP for advanced animations.

a black background with the words why is nothing centered?
a black background with the words why is nothing centered?

For instance, while CSS doesn't have a native way to create a hover effect that persists after the user's mouse leaves the element, this can be achieved using the :active pseudo-class in combination with transition and animation properties.

Conclusion

Understanding why certain CSS properties don't exist can help us appreciate the design of the language and make more informed decisions when coding. While it's frustrating when CSS doesn't have a specific property we need, it's important to remember that there's often a workaround or an alternative solution.

a man is standing in front of a skeleton and the words html vs css
a man is standing in front of a skeleton and the words html vs css
💡 7 CSS Tricks Every Frontend Dev Should Know
💡 7 CSS Tricks Every Frontend Dev Should Know
html/css
html/css
The Ultimate CSS Keyframes Cheat Sheet for Beginners
The Ultimate CSS Keyframes Cheat Sheet for Beginners
Common CSS Mistakes Beginners Must Avoid ❌
Common CSS Mistakes Beginners Must Avoid ❌
10 Best Practices for Quickly Improving Your CSS
10 Best Practices for Quickly Improving Your CSS
Coding - CSS Magic 🪄  #css | Facebook
Coding - CSS Magic 🪄 #css | Facebook
css cheat sheet
css cheat sheet
✨ The Real Difference Between HTML, CSS, and JavaScript ✨
✨ The Real Difference Between HTML, CSS, and JavaScript ✨
Is It Central Sensitivity Syndrome?
Is It Central Sensitivity Syndrome?
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
CSS :has() Selector — The Parent Selector We Always Wanted
CSS :has() Selector — The Parent Selector We Always Wanted
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
the css text - decoration property is displayed on a computer screen
the css text - decoration property is displayed on a computer screen
a man standing in front of a blackboard with the words css comments on it
a man standing in front of a blackboard with the words css comments on it
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes
an image of different types of cats
an image of different types of cats
CSS Cheat Sheet for Beginners (Web Design Basics)
CSS Cheat Sheet for Beginners (Web Design Basics)
a poster with instructions on how to use css
a poster with instructions on how to use css
Challenging CSS Best Practices — Smashing Magazine
Challenging CSS Best Practices — Smashing Magazine
CSS Could Be The Hardest Language of All (5 Reasons Why)
CSS Could Be The Hardest Language of All (5 Reasons Why)