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.

bg-opacity-<value> doesn't work with arbitrary values

See original GitHub issue

Hi, I want to use CSS variables with bg- and found that it doesn’t generate the style to adjust the background opacity.

Here’s playground link

--un-bg-opacity: 1; style is only generated for static class bg-red and not for bg-$c & bg-[red].

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
chu121su12commented, Sep 13, 2022

--un-bg-opacity: 1; style is only generated for static class bg-red and not for bg-$c & bg-[red].

As I understand, util-$value and util-[value] generally use the intended value as is, so usually there are no processing involved.

Thanks for the information. For CSS vars do I have to add each of them to colors as @chris-zhu mentioned above?

For now, you have to add them separately. The rationale is that --x in var(--x) can contain #f00, red, 255, 0, 0, rgb(255, 0, 0) or even any other string.

Another thing you can do maybe is to add custom shortcut

shortcuts: [
  [/^bg2-(.*?)$/, ([_, c]) => `bg-[rgba(var(--${c}),var(--un-bg-opacity,1))]`],
]

BTW, is there docs regarding magic strings/characters like : in bg-custom:50.

Mostly tailwind syntax works: variant:util, [prop:value] and color-util:opacity

2reactions
chu121su12commented, Sep 13, 2022

In bracket, CSS color values are not resolved from theme or keywords. For the keyword part, you may want to add the list of values to the preset.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tailwind css - Focus ring opacity not working with arbitrary value
In your first example: <input type="text" className="focus:ring focus:ring-[rgba(0, 244, 0)]" />. I expect your arbitrary value is being ...
Read more >
Using arbitrary color as rgba() · Discussion #6551 - GitHub
If I do something like bg-[#f03232] , it correctly registers the background color as such, but I'm unable to do the same with...
Read more >
Background Color - Tailwind CSS
Control the opacity of an element's background color using the color opacity modifier. ... You can use any value defined in your opacity...
Read more >
Tailwind CSS Background Opacity - GeeksforGeeks
This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. The bg-opacity is the...
Read more >
How to apply arbitrary styles with tailwind JIT - Educative.io
Unlike component frameworks or libraries, Tailwind doesn't restrict you to preexisting components ... height, and background color using Arbitrary values:
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