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

200
Visualizações
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
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