• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

150
Vistas
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?

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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.

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda