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

208
Visualizações
How to set height in CSS from JavaScript Variable?

So, I am using the Slick slider and wanted to apply some code only when the slider is active.

.specialist-description-wrapper {
height: 0rem;
}
.slick-current.slick-active .specialist-description-wrapper {
height: 20rem;

}

But the problem is, I don't want to have a fixed height. I want an "Auto" height so if my content gets bigger then it'll fit automatically. If I try to make height from 0rem to Auto then "Transition" doesn't work.

So, I have decided to use JavaScript to calculate the height of the element.

    let descriptionWrapper = document.querySelector(".slick-current.slick-active .specialist-description-wrapper")
    let height = descriptionWrapper.offsetHeight
    descriptionWrapper.style.height = height;

But it's not working for me. Did I miss something?

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

0

Keeping the height to auto will only take height used by itself and will not take full height. To make the height responsively adjust according to the parent's height, you can use

height: 100%;

This will make the element take all the height of its parent element.

But still, if anything breaks, you can adjust the content of the element. Because the 100% height is important.


Also, you have not provided enough code regarding your markup. Please always provide the code so that everyone can write better answers for you.

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