Sling Academy
Home/Tailwind CSS/first-of-type and last-of-type in Tailwind CSS

first-of-type and last-of-type in Tailwind CSS

Last updated: December 18, 2023

In CSS, we have the :first-of-type and :last-of-type selectors for targeting the first and the last elements among a group of sibling elements. In Tailwind CSS, the equivalents are the first-of-type and last-of-type modifiers, respectively. Below is a concrete example that makes use of them.

Screenshot:

The code:

<body class="p-40 bg-gray-900">
    <ul class="space-y-5">
        <li class="text-white text-xl 
            first-of-type:text-yellow-500 first-of-type:font-italic
            last-of-type:text-blue-500 last-of-type:underline">
            List Item 1</li>
        <li class="text-white text-xl 
            first-of-type:text-yellow-500 first-of-type:font-italic
            last-of-type:text-blue-500 last-of-type:underline">
            List Item 2</li>
        <li class="text-white text-xl 
            first-of-type:text-yellow-500 first-of-type:font-italic
            last-of-type:text-blue-500 last-of-type:underline">
            List Item 3</li>
        <li class="text-white text-xl 
            first-of-type:text-yellow-500 first-of-type:font-italic
            last-of-type:text-blue-500 last-of-type:underline">
            List Item 4</li>
        <li class="text-white text-xl 
            first-of-type:text-yellow-500 first-of-type:font-italic
            last-of-type:text-blue-500 last-of-type:line-through">
            List Item 5</li>
    </ul>
</body>

That’s it. Happy coding & have fun with Tailwind CSS!

Next Article: :fisrt-child and :last-child in Tailwind CSS

Previous Article: Tailwind CSS: Make a Div 100% Height & Width of the Viewport

Series: Basic Tailwind CSS Tutorials for Beginners

Tailwind CSS

Related Articles

You May Also Like

  • How to Create Striped Tables with Tailwind CSS
  • Tailwind CSS: Creating Shimmer Loading Placeholder (Skeleton)
  • Tailwind CSS: How to Create Parallax Scrolling Effect
  • How to Style Lists in Tailwind CSS
  • Text Underline in Tailwind CSS
  • How to Change Mouse Cursor in Tailwind CSS
  • Form Validation with Tailwind CSS (without Javascript)
  • Tailwind CSS: Create a User Card with Circle Avatar
  • Tailwind CSS: How to Create Columns with the Same Height
  • How to Style Placeholder Text with Tailwind CSS
  • Tailwind CSS: Make a Div 100% Height & Width of the Viewport
  • Using :not() selector in Tailwind CSS
  • Tailwind CSS: How to Create a Stepper
  • Using ::before and ::after in Tailwind CSS
  • Tailwind CSS: How to Create a Vertical Divider Line
  • How to Create Pill Buttons with Tailwind CSS
  • Tailwind CSS: How to Disable Text Selection
  • Tailwind CSS: How to Disable Resizing of Textarea
  • Tailwind CSS: Expand a Text Input on Focus (without Javascript)