Highlight All Items Except the Selected One Using the CSS :not() Selector
📖 Scenario: You are creating a simple webpage with a list of fruits. You want to highlight all fruits except the one that is selected by the user.
🎯 Goal: Build a webpage with a list of fruits where all items except the selected one have a light gray background using the CSS :not() selector.
📋 What You'll Learn
Create an unordered list with exactly five fruit items: Apple, Banana, Cherry, Date, Elderberry
Add a CSS class called
selected to the Banana list itemUse the CSS
:not() selector to style all list items except the one with the selected classSet the background color of the non-selected items to
#f0f0f0Ensure the selected item has no background color
💡 Why This Matters
🌍 Real World
Using the :not() selector helps you style all elements except a specific one, which is common in menus, lists, and interactive UI components.
💼 Career
Front-end developers often use :not() to write cleaner CSS that targets groups of elements while excluding exceptions, improving maintainability and user experience.
Progress0 / 4 steps