question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When I use both p-7 and p-3 in any order the p-7 wins.

In both <div class="p-3 p-7"></div> and <div class="p-7 p-3"></div>, The p-7 applies.

I know that I should use on of them but sometimes I need to apply the same property and override the previous one.

https://play.tailwindcss.com/CHqNNuMYXm

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
miguelcobaincommented, Dec 22, 2020

I do face this problem a lot when building some components. Let’s say you have a button component and by default you always apply a blue background. So you add the class bg-blue.

Many frameworks provide the ability to customize classes applied to the element from the outside.

It is very tempting to write something like this if you want a red button

<MyButtonComponent class="bg-red">
  A button
</MyButtonComponent>

however, the resulting HTML from this component call is

<button class="bg-blue bg-red">
  A button
</button>

if bg-blue comes last in the css file, then it “wins” and the button will not be red.

To solve this I thought about creating a “default” variant, that always comes before any normal utilities. That way the resulting html would be:

<button class="default:bg-blue bg-red">
  A button
</button>

Which should work because any default:* should come before the regular variant (or absence of variant).

Is this possible to do? Do you foresee any problems with this?

Of course, this would have to be used sparingly, only on things that we want to provide a default for and PurgeCSS should help the file sizes to stay low.

1reaction
saeedvazirycommented, Dec 2, 2020

@fedeci Thanks for the advice 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Priority Definition & Meaning - Merriam-Webster
The meaning of PRIORITY is the quality or state of being prior. How to use priority in a sentence.
Read more >
Priorities USA
Priorities USA is a voter-centric progressive advocacy organization and service center for the grassroots progressive movement.
Read more >
Priorities definition and meaning | Collins English Dictionary
Priorities definition: the condition of being prior ; antecedence ; precedence | Meaning, pronunciation, translations and examples.
Read more >
Meaning of priority in English - Cambridge Dictionary
something that is considered more important than other matters: [ C ] The president vowed to make education one of his top priorities....
Read more >
Priorities | The White House
The Biden-⁠Harris Administration Immediate Priorities · COVID-19 · Climate · Racial Equity · Economy · Health Care · Immigration · Restoring America's Global...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found