The hex css value for the added background color does not apply. #12211
-
Hello, I'm trying to make todoList that user can add todo. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hello @Choi-Jinwook! Tailwind doesn't support constructing classes using template strings. To include the class in the build, it needs to see a complete utility class string in the code. You can read more details here - https://tailwindcss.com/docs/content-configuration#dynamic-class-names. To solve your issue, I would recommend using inline styles: // ...
setTodoList(..., background: item.background, ...)
// ...
<div className={...} style={background} />
// ... |
Beta Was this translation helpful? Give feedback.
-
Tailwind doesn’t pick up dynamically generated class names like bg-[${color}]. So, we can't construct class names dynamically. To Fix: const bgColorStyle = card.color ? { backgroundColor: card.color } : {};
return (
<div className="bg-white p-2 rounded-md">
<div onClick={handleClick} className="cursor-pointer transform transition-all duration-300">
<div
style={bgColorStyle}
className="relative h-[250px] bg-opacity-60 rounded-lg shadow-md overflow-hidden"
>
{/* Content */}
</div>
</div>
</div>
); Dynamic styles: style={{ backgroundColor: card.color }} applies any valid CSS color (red, #ff0000, rgb(255,0,0), etc.). Avoid constructing Tailwind class names dynamically. Use inline styles when you need dynamic properties like colors. |
Beta Was this translation helpful? Give feedback.
Hello @Choi-Jinwook!
Tailwind doesn't support constructing classes using template strings. To include the class in the build, it needs to see a complete utility class string in the code. You can read more details here - https://tailwindcss.com/docs/content-configuration#dynamic-class-names.
To solve your issue, I would recommend using inline styles: