Tips and Tricks: CSS Pseudo Class Selectors and Pseudo Elements
Tired of writing JavaScript for simple UI toggles? Discover how to build them with pure CSS using powerful pseudo-classes like `:checked` and `:has()`.
#1about 1 minute
Differentiating between CSS pseudo-classes and pseudo-elements
Learn the key difference between pseudo-classes, which style elements in specific states, and pseudo-elements, which style specific parts of an element.
#2about 1 minute
Simplify complex CSS selectors with the :is pseudo-class
Use the :is() pseudo-class to group multiple selectors and apply shared styles in a more compact and readable way.
#3about 1 minute
Style elements based on a checkbox state with :checked
Update the styles of sibling elements based on the state of a checkbox input using the :checked pseudo-class, without any JavaScript.
#4about 1 minute
Create a pure CSS tooltip with :hover and sibling selectors
Combine the :hover pseudo-class with the next sibling selector (+) to show and hide a tooltip element on button hover.
#5about 1 minute
Conditionally style parent elements using the :has pseudo-class
Apply styles to a parent element only when it contains specific child elements by using the :has() pseudo-class selector.
#6about 1 minute
Insert placeholder content into empty elements with CSS
Use the :empty pseudo-class combined with the ::before pseudo-element to dynamically insert placeholder text into empty divs.
#7about 2 minutes
Create a skewed highlight effect with the ::before pseudo-element
Implement a dynamic, skewed background highlight for text by inserting and styling content with the ::before pseudo-element.
#8about 1 minute
Create newspaper-style text with ::first-line and ::first-letter
Combine the ::first-line and ::first-letter pseudo-elements to apply unique typographic styles for a classic drop cap and introductory line effect.
Related jobs
Jobs that call for the skills explored in this talk.
Matching moments
03:31 MIN
Understanding the DOM structure and pseudo-elements
View-Transition-API: Gamechanger for hybrid app-development
08:04 MIN
Evolving CSS from basic styles to advanced effects
How to write a book with CSS
09:58 MIN
Rediscovering HTML elements and upcoming CSS features
WeAreDevelopers LIVE - Can AI save Accessibility?; Horrid HTML; The Frontend Treadmill and more
17:51 MIN
Discussion on the evolution and future of CSS
What's new in CSS for Designers?
06:49 MIN
Highlighting useful developer tips and tools
WeAreDevelopers LIVE - GraalVM in action, Static Analysis insights and more
04:55 MIN
Core techniques for writing robust and resilient CSS
Future-Proof CSS
03:31 MIN
Improving typography and layout with modern CSS properties
What’s New and What’s Next in Web UI
04:46 MIN
Using the right tool for the right job for accessibility
Tips and Tricks: CSS Pseudo Elements and Pseudo SelectorsCSS is an essential part of web development. Regardless of which programming language you use, the chances are you know some CSS, too. In this article we're going to help you go beyond the basics and explore the power of pseudo elements and pseudo se...
Chris Heilmann
Dev Digest 133 - Back to FrontNews and ArticlesWeAreDevelopers LIVE WebDev Day is on Wednesday, 18/11/2024. Learn about Design-first APIs for UI components, the JavaScript event loop, the Secret sauce behind pattern matching and Vision for websites as well as win a chance to take...
Chris Heilmann
Accessibility tip: Detecting reduced motion in one line of JavaScriptAnimation can be a great tool to make apps seem more performant, be more engaging or even just more interesting. There are, however, quite a few groups of people who can not deal with things animating, as it distracts them or can even cause nausea. T...
Chris Heilmann
Dev Digest 136 - No JS(on) of mineNews and ArticlesDouglas Crockford is our featured video, so let's talk about evolving JavaScript and all things JSON. Judicious JSON explains all the weird things in it, you can learn why it can be incredibly slow, people wonder what even is a JSON ...
From learning to earning
Jobs that call for the skills explored in this talk.