In a sentence: Why does calculations with JS variables does not apply any style using TailwindCSS v3?
I am using VueJS for my project, and this example works as expected as it simply applies calc as string:
...
<div class="w-[calc((100%-12rem)*2/3)]">
...
While this doesn't (there are JS variables involved):
...
<div :class="`w-[calc(${props.languages.length * 1.25 + 3}rem)]`">
...
When I inspect the console, I can see HTML with the correct class:
...
<div class="flex w-[calc(14.25rem)]"
...
... but styles are not applied. Any ideas? What am I doing wrong? I think this is a very powerful feature as it lets you dynamically style your HTML based on underlying data, but I can't make it work although I think am so close.
Thanks in advance.
class=`flex w-[${calculation-result}]`
, leading to - from your example -class=`flex w-[14.25rem]`
(edited after checking the docs). – Stockmon:
to theclass
attribute for Vue to consider it as a "JS string". But I am basically doing what you suggest. – Skepful:
character; given your comment I'm rather glad that I didn't, since I'd probably have raised that as an issue (not knowing that Vue was in use). I have added the vue.js to the question so others are more aware, feel free to edit it back out though. – Stockmon