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

144
Visualizações
How can I make a element show when hovering over another element, and hide it if not. And make it take up space the entire time

So I'm trying to make a header that when hovering over it, it will show a button. And if not, the button will disappear while still taking up space in the layout. I've tried,

.button {
    visibility: hidden;
}

.heading:hover + .button {
      visibility: visible
 }

But the visibility attribute won't change when hovering over it.

I tried using

.button {
    visibility: hidden;
 }

.heading:hover + .button {
    visibility: visible
}

But it didn't work. I expected the visibility attribute to change when hovering over an element with the class “heading”, but it didn't. I am sure that it has detected that I am hovering over it because in a past attempt I used the display attribute, and it worked, just that when I'm not hovering over the heading the button will not take up any space, mildly changing the layout of the page. Old code:

button {
     display: none;
}

.heading:hover + .button {
    display: block;
}

Also, in case you're confused, the “heading” class is applied in the heading element while the “button” class is applied for the button. I was thinking it might need to use JavaScript to make it work, so I added the JavaScript tag. jQuery could also work, but I think it uses the display attribute, which makes the element not take up space when hidden.

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

0

Without see the DOM structure I will suggest you the following css code.

.button {
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}

.heading:hover .button {
  opacity: 1;
  pointer-events: visible;
}

Assuming that your HTML code is something like this:

<div class="heading">
  <a href="#" class="button">YOUR BUTTON</a>
</div>

If you add a + to your CSS selector, you are selecting the next element in the same hierarchy level. To select a child element, as i supose the button is, you have to let a blank space between .parent-element and .child-element as in the example above.

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