如果一个CSS变量的值大于零,我希望隐藏一个元素。我可以让相反情况起作用:
#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%;
}
<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>
然而,我希望上面的示例仅显示红色正方形。有人知道如何用纯CSS实现吗?
opacity: max(calc(1 - var(--ind)*1), 0);
这个怎么样? - Amaury Hanser*1
也是多余的(最初来自实验) - Lee