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

153
Visualizações
Links to change color when clicked, revert back when reloading page

I'm trying to create styles where icons are wrapped in tags. When you click the icon, it will change color so you know it's been clicked. Once you reload the page, the icons will go back to the original unclicked color. This will be used for a page that will have tens/hundreds of icons, in something like a table; so that's why it's important to see what has been clicked.

a {
  text-decoration: none;
}

.dog-icon:before {
  content: "\f6d3";
  font-family: 'Font Awesome 5 Free';
  font-size: 40px;
  font-weight: 900;
  padding: 40px;
}
<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet"/>

  <div style="margin-top: 40px;">
    <a href="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg?crop=1.00xw:0.669xh;0,0.190xh&resize=1200:*" target="_blank" class="dog-icon"></a>
    <a href="https://www.cdc.gov/healthypets/images/pets/angry-dog.jpg" target="_blank" class="dog-icon"></a>
    <a href="https://media.npr.org/assets/img/2021/04/27/prancer_wide-db59609b5bd96c9e56e4dfe32d198461197880c2.jpg?s=1400" target="_blank" class="dog-icon"></a>
    <a href="https://s3-us-west-2.amazonaws.com/uw-s3-cdn/wp-content/uploads/sites/6/2019/10/08113321/Dog-behavior-Kasper-Luijsterburg.jpg" target="_blank" class="dog-icon"></a>
    <a href="https://i.ytimg.com/vi/EVqxcWQOEnU/maxresdefault.jpg" target="_blank" class="dog-icon"></a>
  </div>

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

If you add a bit of JavaScript code, it can be done quite easily:

document.querySelector(".links").onclick=ev=>{if(ev.target.tagName=="A")
  ev.target.className="done"
}
.links a {
  text-decoration: none;
  font-family: 'Font Awesome 5 Free';
  font-size: 40px;
  font-weight: 900;
  margin: 20px;
}
.links a.done { color:green }
<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet"/>

  <div class="links" style="margin-top: 40px;">
    <a href="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg?crop=1.00xw:0.669xh;0,0.190xh&resize=1200:*" target="_blank">&#xf6d3;</a>
    <a href="https://www.cdc.gov/healthypets/images/pets/angry-dog.jpg" target="_blank">&#xf6d3;</a>
    <a href="https://media.npr.org/assets/img/2021/04/27/prancer_wide-db59609b5bd96c9e56e4dfe32d198461197880c2.jpg?s=1400" target="_blank">&#xf6d3;</a>
    <a href="https://s3-us-west-2.amazonaws.com/uw-s3-cdn/wp-content/uploads/sites/6/2019/10/08113321/Dog-behavior-Kasper-Luijsterburg.jpg" target="_blank">&#xf6d3;</a>
    <a href="https://i.ytimg.com/vi/EVqxcWQOEnU/maxresdefault.jpg" target="_blank">&#xf6d3;</a>
  </div>

about 4 years ago · Juan Pablo Isaza Relatório

0

If you just want to know what was clicked and do not want to keep track across page reloads, add one event handler to the window, look for the anchor that was clicked, and add a class.

window.addEventListener("click", function (evt) {
  const link = evt.target.closest("a");
  if (link) link.classList.add("clicked");
});
a {
  text-decoration: none;
}

.dog-icon:before {
  content: "\f6d3";
  font-family: 'Font Awesome 5 Free';
  font-size: 40px;
  font-weight: 900;
  padding: 40px;
}

a.clicked {
  color: green;
}
<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet"/>

  <div style="margin-top: 40px;">
    <a href="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg?crop=1.00xw:0.669xh;0,0.190xh&resize=1200:*" target="_blank" class="dog-icon"></a>
    <a href="https://www.cdc.gov/healthypets/images/pets/angry-dog.jpg" target="_blank" class="dog-icon"></a>
    <a href="https://media.npr.org/assets/img/2021/04/27/prancer_wide-db59609b5bd96c9e56e4dfe32d198461197880c2.jpg?s=1400" target="_blank" class="dog-icon"></a>
    <a href="https://s3-us-west-2.amazonaws.com/uw-s3-cdn/wp-content/uploads/sites/6/2019/10/08113321/Dog-behavior-Kasper-Luijsterburg.jpg" target="_blank" class="dog-icon"></a>
    <a href="https://i.ytimg.com/vi/EVqxcWQOEnU/maxresdefault.jpg" target="_blank" class="dog-icon"></a>
  </div>

about 4 years ago · Juan Pablo Isaza Relatório

0

you can try using the :active selector for your a tags.

for example:

a:active{
(enter css here)
}

i'm new to css so it might not work, but it's worth a try.

about 4 years ago · Juan Pablo Isaza Relatório
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