Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!