less.js icon indicating copy to clipboard operation
less.js copied to clipboard

Alpha hex support

Open Soviut opened this issue 13 years ago • 11 comments
trafficstars

#697 proposes single and double character hex color support (eg: #E would convert to #EEEEEE).

In the spirit of this, I'm proposing support for alpha hex support.

#FF000080

The extra two hex digits at the end would represent the alpha/opacity. LESS could convert this to:

rgba(255, 0, 0, 0.5)

Producing a pure red with 50% opacity.

Soviut avatar Oct 31 '12 08:10 Soviut

will this get in the way of the old IE 8 hex digits? As I remember that begins with alpha.. where as here you would expect it to end in alpha.. Plus I imagine taking an old css sheet and suddenly accepting 8 hex digits and then outputting rgba would also break things.

lukeapage avatar Oct 31 '12 08:10 lukeapage

Yes, while I agree that #RRGGBBAA makes more sense to me, that would indeed clash with argb (#AARRGGBB) that's already in LESS. Admittedly it's done via a function, not a language construct, but it would seem to make sense to use the same format in both if we're to do that.

Synchro avatar Oct 31 '12 08:10 Synchro

I didn't realize IE had 8 digit hex. LESS could still normalize this but it could potentially break existing IE-specific sheets. Somehow, I doubt many people are using said IE-specific hex values these day though.

That, or support the #AARRGGBB format throughout. But I think that is backwards-looking.

Soviut avatar Oct 31 '12 08:10 Soviut

.. just recently someone went to the trouble of extending dotless to leave these type of hex values alone

https://github.com/dotless/dotless/commit/52ba9a4ccf4e9a895d557f01112ab4c7f4cad8a7

TBH I think I see more gain in allowing #E then stepping into the minefield of 8 digit hex

lukeapage avatar Oct 31 '12 08:10 lukeapage

Yes, I don't think this is really worth doing.

Synchro avatar Oct 31 '12 08:10 Synchro

Perhaps as a sub-proposal, some way of indicating that the colour is ARGB vs RGBA?

#RRGGBBAA

versus

##AARRGGBB

or

#RRGGBB,AA
#RRGGBB|AA
#RRGGBB_AA

Soviut avatar Oct 31 '12 08:10 Soviut

closing due to general lack of support for this feature.

lukeapage avatar Dec 06 '12 13:12 lukeapage

Can this be reopened bearing in mind 4 and 8-digit hex are defined in CSS Color Module Level 4 and already supported in various browsers?

ashsearle avatar Nov 17 '17 09:11 ashsearle

I assume Less could auto-convert #RRGGBBAA to rgba()?

matthew-dean avatar Nov 17 '17 18:11 matthew-dean

Yes, it's just a matter of adding add a few lines to handle #4 and #8 cases everywhere (it's not too many) #3 and #6 things are parsed.

seven-phases-max avatar Nov 17 '17 20:11 seven-phases-max

I don't know when it happened, but at some point rgba() became able to convert #rrggbbaa colors to rgba().

Example: box-shadow: 0 3px 6px rgba(#00000029); will output as box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16078431);

It isn't documented but it should be, so I did so in this pull request.

LordPachelbel avatar Jul 02 '21 16:07 LordPachelbel