question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tailwind 3.1.2] Gradient issue: `to-[color]-[number]` is not displayed even if specified

See original GitHub issue

[Tailwind v3.1.2, React v18.1.0, Node v17.0.1, Chrome, Windows]

I copied the example described here and pasted it onto my main (and only) css file. Apparently in version 3.1.2 “via-[color]-[number]” causes a conflict with “to-[color]-[number]”.

When “via-…-…” is added, the gradient shows only the “from-…-…” color and the “via-…-…” color, even if the “to-…-…” color is specified.

(My project has only one css file (screenshot below) and the other styles I apply are inline-classes, but I’ve tried removing them and it doesn’t solve the issue)

Main issue: image

index.css: image

Chrome devtools: image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
adamwathancommented, Jun 12, 2022

Ah that sucks. CRA continues to be a major source of pain for us because of how opinionated it is around PostCSS 😕 Going to close this as not our issue then, but would highly discourage using CRA. Use Vite instead, it an amazing environment for client-side React apps like CRA is, but with a much smoother experience especially with Tailwind 👍

0reactions
rohmanncommented, Jun 11, 2022

No worries! Thanks! I think I figured out the issue here. The @supports rule is coming from the create-react-app stack. My local test env was just following the tailwind docs with React. After ejecting cra and tinkering around, I found the issue goes away when postcss-preset-env is removed.

Simplified, Tailwind outputs the --tw-gradient-to property multiple times.

body {
  @apply bg-gradient-to-tr from-teal-500 via-blue-500 to-cyan-500;
}

produces this:

body {
  --tw-gradient-to: rgb(20 184 166 / 0);
  --tw-gradient-to: rgb(59 130 246 / 0);
  --tw-gradient-to: #06b6d4;
}

Then if postcss-preset-env is involved, it transforms the above to…

body {
  --tw-gradient-to: rgb(20 184 166 / 0);
  --tw-gradient-to: #06b6d4;
}

@supports (color: rgb(0 0 0 / 0)) {
  body {
    --tw-gradient-to: rgb(59 130 246 / 0);
  }
}

…and that causes the color to reset to the other value.

Technically, nothing wrong with the Tailwind CSS output. It looks like an edge case bug in how postcss-preset-env protects rgb colors with slash syntax. They should probably just ignore properties that get redeclared in a different syntax.

That being said, it could be fixed on the Tailwind side if the custom property was only output once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with tailwind css gradient - Stack Overflow
It looks like there is no color schema in your config. Just add this to your tailwind.config.js.
Read more >
Content Configuration - Tailwind CSS
Configuring source paths. Tailwind CSS works by scanning all of your HTML, JavaScript components, and any other template files for class names, ...
Read more >
A guide to adding gradients with Tailwind CSS - LogRocket Blog
In this blog, we'll use Tailwind CSS to create beautiful background, text, border, and underline gradients, as well as animate gradients.
Read more >
Background Colors & Gradients In Tailwind - YouTube
This video will learn you how to use background colors and gradient background colors in Tailwind. Besides, I'll show you how to apply ......
Read more >
CSS class completion doesn't work great with Tailwind 2.1 in ...
Preview (if it is correct version) still does NOT solve the problem ? TailwindCSS plugin still does not show any completion on blade...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found