Skip to content

How to change style inside a component, for example Card component? #84

Closed Answered by satnaing
ferrarafer asked this question in Q&A
Discussion options

You must be logged in to vote

I've used CSS variables for the entire theming 😬.

This approach has some benefits. First of all, we can use more than two themes if we want. Second, we don't have to define styles for dark themes and light themes for each element.
On the other hand, it has some trade-offs. We can no longer use Tailwind's dark variant. To solve this issue, we can do the following approaches.

Method 1: Define custom class in the global style base.css file

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  ...
  html[data-theme="dark"] .my-custom-card {
    background-color: #bb151a;
  }
  html[data-theme="light"] .my-custom-card {
    background-color: #2c6bd8;
  }
  ...
}
...

Then …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ferrarafer
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants