Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use :not() in tailwind.css?

I recently started to give tailwind.css a try in my Nuxt project. so I needed to use :not(:last-child) pseudo-elements but I didn't find how.

  <ul>
    <li
      v-for="(item, index) in items"
      :key="`item-${index}`"
      class="border-solid border-b border-black"
    >
      Item
    </li>
  </ul>

I want to add a border-bottom to all of the <li> except the last one.

I know Tailwind has first & last pseudo-class variant but I can't use them with :not()

like image 395
Reza Majidi Avatar asked Apr 27 '20 09:04

Reza Majidi


People also ask

How do you display none in Tailwind?

Use hidden to set an element to display: none and remove it from the page layout (compare with . invisible from the visibility documentation).

How do you hide an element in Tailwind?

​Use invisible to hide an element, but still maintain its place in the DOM, affecting the layout of other elements (compare with . hidden from the display documentation).

How do you use the last child in Tailwind?

In Tailwind CSS, the equivalents to the :first-child and :last-child pseudo-classes of CSS are the first and last modifiers, respectively. You can use them to style the first/last child of its parent.


1 Answers

The answer is in the link to last in the docs, that you shared.

Just add last:border-b-0 to all list items, and it will remove the border-bottom if it is the last-child.

<ul>
  <li
    v-for="(item, index) in items"
    :key="`item-${index}`"
    class="border-solid border-b border-black last:border-b-0"
  >
    Item
  </li>
</ul>
like image 84
Estevan Maito Avatar answered Sep 26 '22 15:09

Estevan Maito