tailwindcss: The global variable `--tw-transform` is not defined in base

What version of Tailwind CSS are you using?

v3.0.7

What build tool (or framework if it abstracts the build tool) are you using?

tailwindcss-cli 3.0.7

What version of Node.js are you using?

v16.13.0

What browser are you using?

Chrome

What operating system are you using?

macOS

Reproduction URL

https://play.tailwindcss.com/iVIJhwfSBR – Funny thing here: --tw-transform gets directly added to div:after and there is no global definition of that variable. Maybe v3.0.1 is the reason for that 😕

Describe your issue

Edit: It seems like this relates to https://github.com/tailwindlabs/tailwindcss/pull/6500

I am using web components which import a shared CSS file that only contains @tailwind base. When trying to use transform utilities I can also see transform: var(--tw-transform);.

The problem is that the variable is not defined since that does not live in Tailwind base:

*, ::before, ::after {
  ...

  --tw-transform: translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
  ...
}

Is it possible that we get this moved like the other globals like shadows or content?

*, ::before, ::after {
  --tw-ring-offset-shadow: 0 0 #0000;
  --tw-ring-shadow: 0 0 #0000;
  --tw-shadow: 0 0 #0000;
  --tw-shadow-colored: 0 0 #0000;
}
::before,
::after {
  --tw-content: '';
}

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (3 by maintainers)

Most upvoted comments

I have the same issue. I’m using Next.js, Tailwind CSS, twin.macro, and styled-components.

When applying the classes inside the styled-component Div like this, it doesn’t work (with or without the transform class) …

.div {
    ${tw`transform -translate-y-1/2`}
}

However, applying the class -translate-y-1/2 directly to the <div> element inside the component does work perfectly 😕

<div className="-translate-y-1/2">

I’m not sure if it’s a twin.macro issue in my case or is it a configuration issue or what.

In my case, @tailwind base; was not added. After adding transform started working

@adamwathan thanks for your response! The problem in my case is that --tw-transform is not defined. When trying to use rotate-90 I get CSS like this ⬇️

div {
  --tw-rotate: 90deg;
  -webkit-transform: var(--tw-transform);
          transform: var(--tw-transform)
}

I’m still wondering about the global CSS that I can see in tailwind.css ⬇️

*, ::before, ::after {
  --tw-translate-x: 0;
  --tw-translate-y: 0;
  --tw-rotate: 0;
  --tw-skew-x: 0;
  --tw-skew-y: 0;
  --tw-scale-x: 1;
  --tw-scale-y: 1;
  --tw-transform: translateX(var(--tw-translate-x)) translateY(var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
  border-color: currentColor;
  --tw-ring-offset-shadow: 0 0 #0000;
  --tw-ring-shadow: 0 0 #0000;
  --tw-shadow: 0 0 #0000;
  --tw-shadow-colored: 0 0 #0000;
  --tw-blur: var(--tw-empty,/*!*/ /*!*/);
  --tw-brightness: var(--tw-empty,/*!*/ /*!*/);
  --tw-contrast: var(--tw-empty,/*!*/ /*!*/);
  --tw-grayscale: var(--tw-empty,/*!*/ /*!*/);
  --tw-hue-rotate: var(--tw-empty,/*!*/ /*!*/);
  --tw-invert: var(--tw-empty,/*!*/ /*!*/);
  --tw-saturate: var(--tw-empty,/*!*/ /*!*/);
  --tw-sepia: var(--tw-empty,/*!*/ /*!*/);
  --tw-drop-shadow: var(--tw-empty,/*!*/ /*!*/);
  --tw-filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
}

That is not available in my case because I moved the @tailwind base into another file. Also downgrading to v3.0.1 like on play.tailwindcss.com didn’t help 😦

I believe this issue is recurring only in NextJS. I tried the same on Svelte and seemed to work as expected. Maybe there’s some overridden postcss config that’s stopping Tailwind to work as it should?