adding dynamic class name in svelte
I think it was purgeCSS (built-in in tailwind 2.0) that did not recognize the dynamic classes.
It is difficult to solve this problem for every tailwind classes, but if you don't have a lot of these you can manually safe list those classnames:
// tailwind.config.js
module.exports = {
purge: {
content: ['./src/**/*.html'],
// These options are passed through directly to PurgeCSS
options: {
// Generate col-span-1 -> 12
safelist: [...Array.from({ length: 12. }).fill('').map((_, i) => `col-span-${i + 1}`],
},
},
// ...
}
Svelte: Dynamic Tailwind-Class from Variable
By wrapping the svgColor with the curly braces you are effectively making an object with the prop svgColor.
The correct syntax would be:
<p class={svgVisible ? svgColor : ''}>Test</p>
Setting a CSS class based on a variable in Svelte
Use
class={type}
instead of:
class:{type}
Related Topics
How to Use CSS to Reverse The Display Order of Two Elements
Border Collapse Differences in Ff and Webkit
Why Are These Two Inline-Blocks Not Aligned
Prevent Contenteditable Mode from Creating <Span> Tags
Simple Two Column HTML Layout Without Using Tables
Animate Radial-Gradient CSS3: Move from Left to Right
What Is Meant by "Participate" in The Definition of "Normal Flow" in The CSS 2.1 Spec
What Is The Maximum Allowed Negative Value for CSS Left Property
CSS3 Transform: Translate3D Doesn't Affect The Z-Axis
Creating Triangles Using Borders
Calculate Sum Opacity from Layers
Jekyll Liquid Variables as Inline CSS Values
How to Stack Two Same-Sized Canvas on Top of Each Other
Less - Nesting Generates Bad CSS Code
Prevent Linebreak After </Div>
Calculating Background-Position with a Formula in Less CSS