Check out the code (svelte & css) below to see how this is possible.
<script>let value =0;let min =-100;let max =100;// determine if the value is positive or negative, and apply the correct CSS class$: cssClass = value >0?"positive": value <0?"negative":"";// calculate the start position % of the range based on the value$: start = Math.abs(max /2+ value /2);// move the range from either 50%-n% (positive) or n%-50% (negative)$: range = value >0?`--right: ${100-start}%; --left: 50%`:`--left: ${start}%; --right: 50%`;</script><RangeSliderid="pos-neg"class={cssClass}style={range}bind:value{min}{max}suffix="%"formatter={(v) => (v >0?`+${v}`: v <0?`-${Math.abs(v)}`: v)}float/>
#pos-neg {/* set the colors for the positive and negative ranges */--text-color: white; &.positive {--slider-accent: rgb(20, 216, 122);--text-color: rgb(8, 73, 40); } &.negative {--slider-accent: rgb(226, 36, 77);--text-color: rgb(249, 188, 202); }/* create a pseudo element to show the positive / negative range */ &:after {content: '';position: absolute;top: 0;left: var(--left);right: var(--right);height: 100%;background-color: var(--slider-accent);border-radius: inherit;transition: background-color 0.3sease-out; }/* style the handle/float a little */.rangeHandle {width: 32px;height: 32px; }.rangeNub {background: color-mix(in hsl, var(--slider-accent) 15%, white);border: 5pxsolidvar(--slider-accent); }.rangeFloat {opacity: 0.8;translate: -50%-50%0.01px;background: var(--slider-accent);color: var(--text-color);font-weight: 600;transition: all0.2sease-out; } &.rsFocus.rangeFloat {opacity: 1; }}