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

152
Visualizações
How to add the different styles when hover on various elements under single <a> tag using JavaScript or jQuery or CSS

This is my code where am facing issue to add styles:

<div class="panel">
  <a href = "link">
    <img src="abc.jpg"> 
    <h5>Description text</h5>
  </a>
</div>

Requirement:

  1. When hover on the image then H5 text-color can changed in blue color.
  2. When hover on H5 text then the text-color can changed in red color.

Please welcome your fixes either in JavaScript or jQuery or CSS

My try is:

$(".panel a").hover( 
function() { $("h5").css("color","red"); } ); 
$(".panel a").hover( 
function() { $("img").css("color","blue"); } );
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The :hover state is the best way to fix this for the hover over the h5 and img

h5:hover {
   color: red;
   transition: .2s; // makes the color change smootly and not static.
}

img:hover + h5 {
    color: blue;
    transition: .2s;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

maybe this is what you wanted to achive but i suggest if you dont need a to wrap whole content rather than just in h5 for click then replace h5with a as your current layout needs more work to achive simple thing

a {text-decoration:none;}
h5 {text-decoration:underline;color:black;width:max-content;}

h5:hover {
  color:red;
}

img:hover + h5 {
  color:blue;
}
<div class="panel">
<a href = "link">
<img style="height:120px;" src="https://i.ibb.co/hLZrDv0/Hitman-3-artwork.png"> 
<h5>Description text</h5>
</a>
</div>

here is my suggested layout

a{color:black;}
.panel > * {display:block;width:max-content;}
a:hover {
  color:red;
}

img:hover + a {
  color:blue;
}
<div class="panel">
<img style="height:120px;" src="https://i.ibb.co/hLZrDv0/Hitman-3-artwork.png"> 
<a href = "link">Description text</a>
</div>

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