Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda