2

I want to define a variable in a CSS file like this:

:root {
    --sidebar-width: 56;
}

I'd like to now refer to that in a component to define that component's width:

<div className="w-[var(--sidebar-width)]">
   <MySidebar>
</div>

This doesn't work. What I'm trying to achieve is to add the w-56 class to that component and to do so as a variable so that I can refer to that variable in several places. Is this possible and if so, how do I specify this?

1 Answer 1

2

I'm pretty sure it's impossible.
Just do this instead:

:root {
    --sidebar-width: 56;
}

<div className="w-[calc(4px*var(--sidebar-width)]">
   <MySidebar>
</div>

1 tailwind unit is 4px.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.