Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

First, Last, Odd

Now let's look at the opening hours. They're a list in which each row is an li element with the day on the left and the hours on the right. Long lists like this are easier to read when every other row has a different background: your eyes don't slip to the wrong line.

Tailwind has variants for an element's position among its siblings, the children of the same parent:

VariantApplies toCSS
first:the first child:first-child
last:the last child:last-child
odd:the 1st, 3rd, 5th... child (odd):nth-child(odd)
even:the 2nd, 4th, 6th... child (even):nth-child(even)

Watch out: the class goes on every row, not on the list. Each row checks for itself whether it's odd (or the first, or the last), and only then does the class apply. That's why all the rows have the same classes, and when you add or remove a row, the stripes still take turns correctly.

<ul>
	<li class="odd:bg-stone-100">Monday</li>
	<li class="odd:bg-stone-100">Tuesday</li>
	<li class="odd:bg-stone-100">Wednesday</li>
</ul>

The rows are also separated by lines: each has a border at the bottom (border-b). The last row doesn't need one, because the list ends there anyway. The class last:border-b-0 removes the border from the last row only.

Instructions

  1. 1

    Add the class odd:bg-stone-100 to all seven rows of the opening hours.

  2. 2

    Add the class last:border-b-0 to all seven rows.

Back

8/9

  1. 1. Hover
  2. 2. Smooth Changes
  3. 3. Cursor and Clicking
  4. 4. Styling Form Fields
  5. 5. Focus
  6. 6. Disabled Buttons
  7. 7. Hovering Over a Card
  8. 8. First, Last, Odd
  9. 9. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.