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

149
Views
Obtenga las alturas de los elementos cargados y agregue la regla css

Tengo una cantidad de elementos de diferentes tamaños en una página, todos con la misma clase de .margin-top-auto

No puedo saber las alturas de los elementos hasta que se carga la página.

Necesito agregar {margin-top = the height of each element} a estos elementos al cargar la página.

Buscando un fragmento jQuery/Vanilla que lograría esto por mí.

Muchas gracias.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede obtener el offsetHeight del elemento:

 const height = div.offsetHeight; div.style.marginTop = height + 'px' console.log(height)
 #div{ background-color:black; height:100px; width:100px; }
 <div id="div"></div>

Para apuntar a múltiples elementos, puede hacer lo siguiente:

 document.querySelectorAll('.margin-top-auto').forEach(e => e.style.marginTop = e.offsetHeight + 'px')
 .margin-top-auto{ height:100px; width:100px; background-color:black; } .row{ display:flex; }
 <div class="row"> <div class="margin-top-auto"></div> <div class="margin-top-auto"></div> <div class="margin-top-auto"></div> </div>

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!