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

188
Vistas
Is there a way to use css with an If/else condition?

I am making a memory game for school. My issue right now is, you can spam click everything and everything will show.

whenever you have the wrong pair the cards make the class "red" and they turn red in the css code. But you're still able to click the other cards and a few turn back to normal again after 600ms, some just stay and don't turn back.

is it possible to use an if/else condition for css? If there are "red" cards, the pointer event for normal cards are none. You can play the game here and test the issue yourself: https://memory-20.815374.repl.co

Fixing it without If/else is fine too. Using if/else is just the first thing that comes in my head.

here is the code for CSS:

.card.clicked {
  background-color: orange;
  pointer-events: none;
}
                      
.card.checked {
  background-color: lightgreen;
  visibility: hidden;
  transition: visibility 0s linear 300ms, opacity 300ms;
}

.card.clicked img,
.card.checked img {
  opacity: 1;
}

.card.red {
  background-color: #f15f5f;
}

.card {
  height: 120px;
  width: 100px;
  background-color: #ff5cbb;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: 0.3s all ease;
}

Here is the JavaScript code:

          } else {
              const incorrectCards = document.querySelectorAll(".card.clicked");
      
              incorrectCards[0].classList.add("red");
              incorrectCards[1].classList.add("red");            
        
              setTimeout(() => {
                incorrectCards[0].classList.remove("red");        
                incorrectCards[0].classList.remove("clicked");
                incorrectCards[1].classList.remove("red");
                incorrectCards[1].classList.remove("clicked");
              }, 600);
about 4 years ago · Juan Pablo Isaza
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