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

226
Visualizações
Height of the Inner Content doesn't get changed when changing the container height

I want the 3rd element to take the place of the element second when clicked on the button, I know I can use .remove() to remove that specific block of code, but it will not gonna transition, so I want the third element to take place of the second with transition instead of direct getting there. How can I do that? I try to do the example but changing the height of the 2nd container, but the inner Content didn't change and it also didn't transition even though I have set the transition on the height

const btn = document.getElementById('btn');

btn.addEventListener('click', () => {
    const all = document.querySelectorAll('.cont');
  all[1].classList.add('changeheight');
})
.changeheight {
  height: 0px;
  transition: height 250ms ease;
}
<div class="cont"><h1>Hello 1</h1></div>
<div class="cont"><h1>Hello 2</h1></div>
<div class="cont"><h1>Hello 3</h1></div>
<div class="cont"><h1>Hello 4</h1></div>


<button id="btn">
  Click
</button>

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

0

const btn = document.getElementById('btn');

btn.addEventListener('click', () => {
  const all = document.querySelectorAll('.cont');
  all[1].classList.add('changeheight');
})
* {
  margin: 0;
  padding: 0;
}

.cont {
  height: 50px;
}

.changeheight {
  height: 0px;
  transition: height 350ms ease;
}
<div class="cont">
  <h1>Hello 1</h1>
</div>
<div class="cont">
  <h1>Hello 2</h1>
</div>
<div class="cont">
  <h1>Hello 3</h1>
</div>
<div class="cont">
  <h1>Hello 4</h1>
</div>


<button id="btn">
        Click
    </button>

about 4 years ago · Juan Pablo Isaza Relatório

0

Add overflow: hidden to changeHeight class and take some idea from @CyrusKabir answer

const btn = document.getElementById('btn');

btn.addEventListener('click', () => {
    const all = document.querySelectorAll('.cont');
  all[1].classList.add('changeheight');
})
* {
  margin: 0;
  padding: 0;
}

.cont {
  height: 50px;
}

.changeheight {
  height: 0px;
  transition: height 550ms ease;
  overflow: hidden;
}
<div class="cont">
  <h1>Hello 1</h1>
</div>
<div class="cont">
  <h1>Hello 2</h1>
</div>
<div class="cont">
  <h1>Hello 3</h1>
</div>
<div class="cont">
  <h1>Hello 4</h1>
</div>


<button id="btn">
        Click
    </button>

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