Classes setting colour set RGB value but not hex
See original GitHub issueGiven a tailwind class to set a background colour like this:
.bg-off-black {
--bg-opacity: 1;
background-color: #131b20;
background-color: rgba(19, 27, 32, var(--bg-opacity));
}
If I set it via: className='bg-off-black'
I get an output of this:
This is correct as hex and rgb are applied.
Using the tw='bg-off-black'
or using it in a styled-component ${tw`bg-off-black`}
prop
This mostly proves a problem for me setting up ie11 compatibility as the variables which set opacity are failing so that method isn’t working (not worked out why just yet), either way the hex values should still be applied I believe?
CodeSandbox example: https://codesandbox.io/s/busy-moser-yxl7g?file=/src/App.tsx
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
javascript - How to get hex color value rather than RGB value?
TL;DR. Use this clean one-line function with both rgb and rgba support: const rgba2hex = (rgba) => `#${rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?
Read more >HEX vs RGB vs HSL: What is the Best Method to set CSS ...
When it comes to animating the colors, RGB and HSL are preferable over Hex, and their additional channel for alpha value comes in...
Read more >How to Read Hex Color Codes - Hexadecimal Color | Pluralsight
A good place to start before moving on to reading hex color codes is learning how to understand RGB colors. RGB numbers are...
Read more >Defining Colors in CSS
There are several different ways to specify colors in CSS. ... RGB colors have three values that represent: red, green, and blue; Each...
Read more >Setting Accessible RGB Values from Hex Codes in PowerPoint
PowerPoint uses RGB values for a color. RGB stands for red, greeb, blue and the accessibility checker find hex codes, To convert hex...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I seeeee, okay cool not to worry! Before I remove I’m gonna try adding css-vars-ponyfill and see if I can just set the --bg-opacity to 1 (doubt I’ll need the opacity set, and if I do I’m using styled-components so i can get around it). Otherwise I’m sure I’ll see you again when I get to my next project where I will hopefully not be forced to support ie11!
Keep up the good work and thanks for the help 😃
FWIW: to anyone else who might face this, the css-vars-ponyfill did successfully allow me to continue using twin (weigh up whether this makes a difference to you yourselves).
In Tailwind, disabling the text and background opacity would remove the variables but this is not case for twin.macro.
this is adding some unnecessary overhead, in my case i’m using twin.macro to animate object properties so I would prefer to only manipulate the background or color properties(as it should).