Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
Hide an html element if a css var is greater than some value

I'd like hide an element if a css var is greater than zero. I can get the inverse case to work:

#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>

However, I'd like to have the above example show only the red sqare. Can anyone see how to do this (in pure css)?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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

.item {
  opacity: min(calc( 1 - var(--ind)), 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>

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda