如果 css var 大于某个值,则隐藏 html 元素

ato*_*3ls 5 html css opacity

如果 css var 大于零,我想隐藏一个元素。我可以让相反的情况起作用:

#container {
  display: flex;
  width: 100%;
  height: 30px;
  border: 1px soild black;
}

.item {
  opacity: max(calc( var(--ind)*1), 0);
/* or clamp(var(--ind), 0 , 1);*/
  width: 30px;
  height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
  <div class="item" style="--ind: 0;background-color:red;"></div>
  <div class="item" style="--ind: 1;background-color:orange;"></div>
  <div class="item" style="--ind: 2;background-color:yellow;"></div>
  <div class="item" style="--ind: 3;background-color:green;"></div>
  <div class="item" style="--ind: 4;background-color:blue;"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

但是,我想让上面的示例仅显示红色方块。任何人都可以看到如何做到这一点(在纯CSS中)?

ato*_*3ls 0

#container {
  display: flex;
  width: 100%;
  height: 30px;
  border: 1px soild black;
}

.item {
  opacity: min(calc( 1 - var(--ind)), 1);
  width: 30px;
  height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
  <div class="item" style="--ind: 0;background-color:red;"></div>
  <div class="item" style="--ind: 1;background-color:orange;"></div>
  <div class="item" style="--ind: 2;background-color:yellow;"></div>
  <div class="item" style="--ind: 3;background-color:green;"></div>
  <div class="item" style="--ind: 4;background-color:blue;"></div>
</div>
Run Code Online (Sandbox Code Playgroud)