Styling List Items Using the Nth-child Selector
📖 Scenario: You are creating a simple webpage that shows a list of fruits. You want to make every third fruit in the list appear with a different background color to make it stand out.
🎯 Goal: Build a webpage with a list of fruits and use the CSS nth-child selector to color every third item in the list with a light green background.
📋 What You'll Learn
Create an HTML unordered list with exactly six fruit names as list items.
Add a CSS rule using the
nth-child(3n) selector to style every third list item.Set the background color of every third list item to
#d4edda (a light green).Ensure the page uses semantic HTML and the CSS is properly linked or embedded.
💡 Why This Matters
🌍 Real World
Using the nth-child selector helps highlight specific items in lists or tables, making content easier to scan and visually appealing.
💼 Career
Web developers often use nth-child selectors to style repeating patterns in lists, menus, or grids without adding extra classes or IDs.
Progress0 / 4 steps