Styling List Items with First-child and Last-child in Tailwind CSS
📖 Scenario: You are creating a simple webpage that shows a list of fruits. You want to style the first and last items in the list differently to make them stand out.
🎯 Goal: Build an HTML list of fruits and use Tailwind CSS classes to style the first item with a green background and the last item with a blue background using first: and last: variants.
📋 What You'll Learn
Create an unordered list with exactly 5 fruit names as list items.
Use Tailwind CSS
first:bg-green-200 to style the first list item with a light green background.Use Tailwind CSS
last:bg-blue-200 to style the last list item with a light blue background.Ensure the list is inside a
<main> element with proper semantic HTML.Make sure the page is responsive and uses semantic HTML5 elements.
💡 Why This Matters
🌍 Real World
Styling lists with first-child and last-child selectors is common in menus, navigation bars, and item lists to highlight important elements.
💼 Career
Understanding how to use Tailwind CSS variants for pseudo-classes like first-child and last-child helps you build visually appealing and accessible user interfaces quickly.
Progress0 / 4 steps