Skip to content
Discussion options

You must be logged in to vote

Hello! This CSS leakage issue is common when building component libraries with Tailwind. Here are the recommended solutions:

Solution 1: CSS-in-JS with Scoped Styles

import { styled } from '@stitches/react';

const StyledButton = styled('button', {
  backgroundColor: 'var(--primary-color)',
  padding: '0.5rem 1rem',
});

export const Button = ({ children }) => {
  return <StyledButton>{children}</StyledButton>;
};

Solution 2: Tailwind CSS Layer Scoping

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

@layer components {
  .btn-primary {
    @apply bg-blue-500 text-white px-4 py-2 rounded;
  }
  
  .card {
    @apply bg-white shadow-lg rounded-lg p-6;
  }
}

Solution 3: CSS Modul…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by SukhorukovS
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
Help
Labels
None yet
3 participants