Skip to content

Commit 6854406

Browse files
author
Chris Lilley
committed
[css-color-5] fix w3c#4732 with spec text and adam's example
1 parent b763e3d commit 6854406

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

css-color-5/Overview.bs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,36 @@ Selecting the most contrasting color: the ''color-contrast()'' function {#colorc
287287

288288
</div>
289289

290+
The colors in the list are tested sequentially,
291+
from left to right;
292+
a color is the temporary winner
293+
if it has the highest contrast of all those tested so far,
294+
and once the end of the list is reached, the current temporary winner is the overall winner.
295+
Thus, if two colors in the list happen to have the same contrast,
296+
the earlier in the list wins
297+
because the later one has the same contrast, not higher.
298+
299+
<div class="example">
300+
<pre class="lang-css">
301+
foo {
302+
--bg: hsl(200 50% 80%);
303+
--purple-in-hsl: hsl(300 100% 25%);
304+
color: color-contrast(var(--bg) hsl(200 83% 23%), purple, var(--purple-in-hsl));
305+
}
306+
</pre>
307+
308+
The calculation is as follows:
309+
310+
* <span class="swatch" style="--color: hsl(200 50% 80%)"></span> --bg is rgb(179 213 230) which has relative luminance 0.628835
311+
* <span class="swatch" style="--color: hsl(200 83% 23%)"></span> hsl(200 83% 23%) is rgb(10 75 107) which has relative luminance 0.061575 and contrast ratio 6.08409
312+
* <span class="swatch" style="--color: purple"></span> purple is rgb(128 0 128) which has relative luminance 0.061487 and contrast ratio 6.08889
313+
* <span class="swatch" style="--color: hsl(300 100% 25%)"></span> --purple-in-hsl is also rgb(128 0 128) which has relative luminance 0.061487 and contrast ratio 6.08889. This is not greater than the contrast for purple, so purple wins.
314+
315+
The calculated values here are shown to six significant figures, to demonstrate that early rounding to a lower precision would have given the wrong result (0.061575 is very close to 0.061487;
316+
6.08409 is very close to 6.08889).
317+
<!-- great example to use in WPT -->
318+
</div>
319+
290320
Modifying colors {#colormodify}
291321
===============================
292322

0 commit comments

Comments
 (0)