Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda