Replies: 2 comments 2 replies
-
There is a way to apply these rules in Tailwind with default configuration. Use
|
Beta Was this translation helpful? Give feedback.
-
To achieve this effect more idiomatically in Tailwind CSS, you can leverage opacity classes and customize colors in your tailwind.config.js. Here are two approaches: 1. Using Tailwind's Built-in Opacity ClassesTailwind natively supports managing opacities combined with colors. For example: <div class="bg-black bg-opacity-10"></div>
<div class="bg-white bg-opacity-20"></div> This approach achieves the same results as your custom CSS classes while reducing the need for additional custom styles. 2. Customizing Colors in tailwind.config.jsIf you prefer specific names like black-glass and white-glass, you can extend the Tailwind configuration to include them as custom colors: // tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
'black-glass': {
10: 'rgba(0, 0, 0, 0.1)',
20: 'rgba(0, 0, 0, 0.2)',
30: 'rgba(0, 0, 0, 0.3)',
40: 'rgba(0, 0, 0, 0.4)',
50: 'rgba(0, 0, 0, 0.5)',
60: 'rgba(0, 0, 0, 0.6)',
70: 'rgba(0, 0, 0, 0.7)',
80: 'rgba(0, 0, 0, 0.8)',
90: 'rgba(0, 0, 0, 0.9)',
},
'white-glass': {
10: 'rgba(255, 255, 255, 0.1)',
20: 'rgba(255, 255, 255, 0.2)',
30: 'rgba(255, 255, 255, 0.3)',
40: 'rgba(255, 255, 255, 0.4)',
50: 'rgba(255, 255, 255, 0.5)',
60: 'rgba(255, 255, 255, 0.6)',
70: 'rgba(255, 255, 255, 0.7)',
80: 'rgba(255, 255, 255, 0.8)',
90: 'rgba(255, 255, 255, 0.9)',
},
},
},
},
}; This allows you to use classes like: <div class="bg-black-glass-10"></div>
<div class="bg-white-glass-50"></div> |
Beta Was this translation helpful? Give feedback.
-
I often add the following to my projects to easily set translucent backgrounds in my app. Is there a better way to achieve this in tailwind? And would it be possible to ship similar classes with tailwind by default?
Beta Was this translation helpful? Give feedback.
All reactions