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.

Classes setting colour set RGB value but not hex

See original GitHub issue

Given 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: image 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 image

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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kieran-osgoodcommented, Jun 5, 2020

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).

0reactions
cybervaldezcommented, Oct 12, 2020

In Tailwind, disabling the text and background opacity would remove the variables but this is not case for twin.macro.

// tailwind.css (original)
.bg-red-400 {
  --bg-opacity: 1;
  background-color: #fc8181;
  background-color: rgba(252, 129, 129, var(--bg-opacity));
}

// tailwind.config.js
  corePlugins: {
    textOpacity: false,
    backgroundOpacity: false,
  },

// tailwind.css (with above settings)
.bg-red-400 {
  background-color: #fc8181;
}

// twin.macro
console.log(tw`bg-red-400`) // { --bg-opacity: "1", backgroundColor: "rgba(252, 129, 129, var(--bg-opacity))"}

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).

Read more comments on GitHub >

github_iconTop 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 >

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