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

174
Vistas
How to set a rectangle on the top center of another rectangle with pure JS

I would like to get the result like this expected. The actual problem is a div will be displayed on the top center of an icon ( behaviour like a tooltip). I have tried the following code:

const iconPosition= this.el.nativeElement.getBoundingClientRect();

const divPosition= this.div.getBoundingClientRect();

let top;
let left;

if (this.placement === 'top') {
  top = iconPosition.top - divPosition.height;
  left = iconPosition.left + (iconPosition.width - divPosition.width) / 2;
} 

The top works fine but I have an issue with the left. It leads me to this result: current

Could someone help? I got stuck for two days now. Any support is greatly appreciated! Thank you all!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just as an input: Can it be, that the part: (iconPosition.width - divPosition.width) / 2 is negative? So you are going to move thed upper div to the left instead to the right Math.abs(); might help, but without code......

about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda