Skip to content

Commit 25a3464

Browse files
committed
[css-color-5] Lab Example
1 parent 8095c0e commit 25a3464

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

css-color-5/Overview.bs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Adjusting colors: the ''color-adjust'' function {#coloradjust}
240240
Relative color syntax {#relative-colors}
241241
--------------------------------------------------------
242242

243-
Besides specifying absolute coordinates, all color functions can also be used with a *relative syntax* to produce colors in the function's target color space, based on an existing color (henceforth referred to as "origin color"). This syntax consists of the keyword `from`, a <<color>> value, and optionally numerical coordinates specific to the color function. To allow calculations on the original color's coordinates, there are single-letter keywords for each coordinate and `alpha` that corresponds to the color's alpha. If no coordinates are specified, the function merely converts the origin color to the target function's color space.
243+
Besides specifying absolute coordinates, all color functions can also be used with a *relative syntax* to produce colors in the function's target color space, based on an existing color (henceforth referred to as "origin color"). This syntax consists of the keyword ''from'', a <<color>> value, and optionally numerical coordinates specific to the color function. To allow calculations on the original color's coordinates, there are single-letter keywords for each coordinate and `alpha` that corresponds to the color's alpha. If no coordinates are specified, the function merely converts the origin color to the target function's color space.
244244

245245
The following sections outline the relative color syntax for each color function.
246246

@@ -309,6 +309,17 @@ When an origin color is present, the following keywords can also be used in this
309309
- 'b' is a <<number>> that corresponds to the origin color's CIELab b axis
310310
- 'alpha' is a <<percentage>> that corresponds to the origin color's alpha transparency
311311

312+
<div class="example">
313+
Multiple ways to adjust the transparency of a base color:
314+
315+
* ''lab(from var(--mycolor) l a b / 100%)'' sets the alpha of ''var(--mycolor)'' to 100% regardless of what it originally was.
316+
* ''lab(from var(--mycolor) l a b / calc(alpha * 0.8))'' reduces the alpha of ''var(--mycolor)'' by 20% of its original value.
317+
* ''lab(from var(--mycolor) l a b / calc(alpha - 20%))'' reduces the alpha of ''var(--mycolor)'' by 20% of 100%.
318+
319+
Note that all the adjustments are lossless in the sense that no gamut clipping occurs, since lab() encompasses all visible color.
320+
This is not true for the alpha adjustments in the sRGB based functions (such as'rgb()', 'hsl()', or 'hwb()'), which would also convert to sRGB in addition to adjusting the alpha transparency.
321+
</div>
322+
312323
<h4>Relative LCH colors</h4>
313324

314325
The grammar of the ''lch()'' function is extended as follows:

0 commit comments

Comments
 (0)