tailwind-children icon indicating copy to clipboard operation
tailwind-children copied to clipboard

Specificity issue with base styles

Open dannyuk1982 opened this issue 3 years ago • 4 comments

Because where: always has a specificity of 0 I am finding the base reset is overwriting the rule for a child, i.e

<div class="child:mb-5">
  <p>This will have a margin bottom of 0</p>
</div>
image

Swapping where: to is: might fix?

dannyuk1982 avatar May 16 '22 09:05 dannyuk1982

hmmm, not sure why that didn't show up in testing.

If we switch it to is I imagine that the parent would have a higher specificity than the child, which would be a problem when you want to override the rules.

<div class="child:mb-5">
  <p class="mb-3">Will this have a margin bottom of 5 (1.25rem) or 3 (0.75rem)</p>
</div>

I think I saw a write up on a hack putting the where into the is.... I am really limited on time this week, but can you test and see what happens with the is and child overrides?

Thanks!

SamGoody avatar May 16 '22 10:05 SamGoody

If I get any time myself I will have a play!

dannyuk1982 avatar May 16 '22 10:05 dannyuk1982

Hi, don't want to be that guy who just swings by and leaves a +1 but since there's no update on this, I just wanna check in and see how things are going.

Let me know if there's something I can do to help. Happy to find some time and dive into this as well!

alexluong avatar Oct 01 '22 17:10 alexluong

Sorry, but am way overloaded at work.

In the latest versions of tailwind you can use arbitrary variants [&>*] and it will apply to all children with a higher specificity than the default rules.

<div class="[&>*:mb-5">
  <p>This will have a margin bottom of 0</p>
</div>

This has the disadvantage of clouting the children classes as well. The real fix is that the default style sheet (the normalize.css) should really have :where() added to remove all specifity from normalized files.

For now though, I hope this helps. Good luck!

SamGoody avatar Oct 07 '22 12:10 SamGoody