Definitely!
If you are open to utilizing CSS variables, it is completely feasible to create 2 or 3 color gradients.
You can employ CSS color-mix
along with CSS variables to accomplish a color blend based on a variable value.
Simply utilize the following CSS:
.highlight-color {
--min: 0;
--max: 1;
--incs: oklch;
--value: 0.5;
--high-color: #F8696B;
--middle-color: #FFEB84;
--low-color: #63BE7B;
}
.highlight-color .highlightme {
/* This is where the magic happens */
--normed: calc(100% * (var(--value) - var(--min))/(var(--max) - var(--min)));
}
.highlight-color.highlight-2color .highlightme {
background-color: color-mix(
in var(--incs),
var(--high-color) var(--normed),
var(--low-color)
);
}
.highlight-color.highlight-3color .highlightme {
--n1: calc((var(--normed) - 50%) * 2);
--n2: calc(var(--normed)*2);
background-color: color-mix(
in var(--incs),
color-mix(in var(--incs), var(--high-color) var(--n1), var(--middle-color)) var(--normed),
color-mix(in var(--incs), var(--middle-color) var(--n2), var(--low-color))
);
}
Next, include the following HTML:
<table>
<tbody>
<tr class="highlight-color highlight-3color" style="--min: 0; --max: 1;">
<td class="highlightme" style="--value: 0.00;">0.00</td>
<!-- other td elements here -->
<td class="highlightme" style="--value: 1.00;">1.00</td>
</tr>
</tbody>
</table>
Upon executing this setup correctly, you will achieve the desired effect.
For automated setting of CSS values, consider using the provided Javascript snippet:
document.querySelectorAll('.autohighlight').forEach(el => {
const values = [];
const els = el.querySelectorAll('.highlightme');
els.forEach(vel => {
values.push(vel.innerText / 1);
vel.style.setProperty('--value', vel.innerText / 1);
});
const max = Math.max(...values);
const min = Math.min(...values);
el.style.setProperty('--min', min);
el.style.setProperty('--max', max);
});
To see this concept in action, check out an example codepen here.