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

199
Views
React Application Width not being applied to element

I have the following div elements in my component:

       <div className={`max-h-5/6 flex flex-row mx-auto`} style={{ width: '100%'}} id="wallViewContainer">
             <div className="h-full w-full my-auto justify-center flex flex-1" data-testid="wallView">
       </div>
       <div className="h-10 pb-8 w-full flex flex-row justify-between items-center" id="bottomDiv">

On each render I am checking if the wallView div is overflowing the bottomDiv, if it is, I want to scale the width of the wallViewContainer down

  const wallViewDiv = document.querySelector('[data-testid="wallView"]')
  const bottomDiv = document.getElementById('bottomDiv')
  const wallViewContainer = document.getElementById('wallViewContainer')
  var wallRect = wallViewDiv?.getBoundingClientRect();
  var btmRect = bottomDiv?.getBoundingClientRect();

  if (wallRect && btmRect && wallViewContainer) {
    let currWidth = wallViewContainer?.style?.width?.split('').slice(0, 3).join('')
    const overflow = wallRect.bottom > btmRect.top

    if (overflow) {
      let percentOverflow = ((wallRect.height - btmRect.top) / wallRect.bottom * 100)
      wallViewContainer.style.width = Math.round((parseInt(currWidth) - percentOverflow)).toString() + "%"
    }
    else {
      wallViewContainer.style.width = "100%"
    }
  }

However, when I change my wallViewContainer.style.width to the new width, it is not applying and still shows 100% in dev tools in chrome.

But weirdly enough if i change it like this wallViewContainer.style.width = "42%" it does apply.

I have checked to make sure Math.round((parseInt(currWidth) - percentOverflow)).toString() + "%" computes a string with a whole number followed by a percent...any ideas?

about 4 years ago · Juan Pablo Isaza
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!