-
Notifications
You must be signed in to change notification settings - Fork 717
[css-color] HEX Color Opacity Handling #6880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
CSS Color 5 ED (subject to change): color: rgb(from var(--red-hex) r g b / var(--color-opacity)); |
Hi. Thank you. I stand corrected, I totally missed this change. Should I close the issue or leave it as an alternative possible solution? |
The solution proposed by Crissov does not work for me:
I assume this is not implemented yet? Sorry for my ignorance - but where can I check the current status? Caniuse doesnt have anything on "Relative Color Syntax" or "from var". |
As usual, not supported by Firefox... |
Check it here |
The issue:
As it is written in reference you can very easily work with
rgb()
andhsl()
and their semi-transparent / transparent variant functionsrgba()
andhsla()
.Hex code can use format
#FFFFFF
or transparent / semi-transparent version#FFFFFFFF
.Problem occures when you you want to use CSS Variables for adding transparency in to color.
Example:
We have a color red with code in variable for:
rgb:
--red-rgb: 255, 0, 0;
hsl:
--red-hsl: 0, 100%, 50%;
hex:
--red-hex: #FF0000;
and opacity for different background where you do not want to use fully saturated color:
--color-opacity: 0.5;
So making those colors with opacity:
rgba(var(--red-rgb),var(--color-opacity));
hsla(var(--red-hsl), var(--color-opacity));
are easy to make but for hex it is not doable. You need to make another css variable with full format, in this case it will be hex with opacity:
--red-hex-opa: #FF0000F0;
And since I for example need to change opacity only in the future or just the color, I would need to change whole color code in hex opacity instead of changing it in one place.
Proposal:
New function will be introduced called
hexa()
for example which will work same asrgba()
orhsla()
.When working with opacity and hex code color it will support css variables:
hexa(var(--hex-red), var(--color-opacity));
which will generatehex: #FF0000F0
or browser readable optionhexa()
would be functional instead. With that you will have option to use hex in#FFFFFFFF
orhexa()
function when introducion transparency in to the color.Knowledge:
I am aware that when making web and css styling, I can change all hex codes from designs in to RGB or HSL format respectively and just simply use
rgba()
orhsla()
functions instead of making new one. This is idea about having all color formats with consistent functions since<color>
is worked on currently.References:
https://www.w3schools.com/css/css3_colors.asp - reference for color opacity functions
The text was updated successfully, but these errors were encountered: