I do want to convert this to Tailwind
<div
style={{
width: 0,
height: 0,
borderLeft: "9px solid transparent",
borderRight: "9px solid transparent",
borderBottom: `8px solid ${
isCardExpired ? "rgb(250,77,86)" : "rgb(232,125,26)"
}`,
marginLeft: "auto",
marginRight: "auto"
}}
></div>
This will generate a triangle shape in CSS.
So far I tried to convert it like this
<div className="w-0 h-0 border-x-8 border-solid border-transparent mx-auto"></div>
How do I add this part
borderBottom: `8px solid ${
isCardExpired ? "rgb(250,77,86)" : "rgb(232,125,26)"
}`
This is my Code sandbox link
2
Answers
You can use a utility like tailwind-merge or clsx like this:
You can also add the
rgb
colors to your theme for easier use:And then use it as:
Edit: explanation of Tailwind border dimensions are here. You already have
border-x-8 border-solid
which is not part of the conditional, so it will work as you posted. If you need the width and height to be 8px, then you can change theborder-x-8
toborder-8
. If as you stated only bottom thenborder-b-8
instead ofborder-x-8
.You can use your code like in below example:
However what you are trying to achieve is difficult through tailwind CSS, as Tailwind CSS is primarily designed for utility-first and atomic CSS classes. Complex border styling like the one you described might not be achievable with Tailwind classes alone. You will have to use like below