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

115
Views
¿Cómo autoajustar el lienzo en la división principal?

Tengo un lienzo dentro de div:

 <div class="preview"><canvas id="cropped" width="2480" height="2003"></canvas></div>

El bloque div es menor que el lado del lienzo. Cómo autoajustar el lienzo en dos casos:

  1. ajuste automático del ancho del lienzo proporcional al div del ancho de los padres
  2. ajuste automático de la altura del lienzo proporcional a la división de altura principal

Intenté de esta manera:

 public autofit = (orientation: RegistryOrientation) => { let previews = document.getElementsByClassName('preview'); if (previews.length > 0) { let preview = previews[0]; let width = preview.clientWidth; let height = preview.clientHeight; if (orientation === RegistryOrientation.album) { this.imgCanvas.style.width = width + 'px'; this.imgCanvas.style.height = 'auto'; } else if (orientation === RegistryOrientation.book) { this.imgCanvas.style.height = height + 'px'; this.imgCanvas.style.width = 'auto'; } } };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Simplemente puede usar el símbolo '%' para indicar la altura proporcional del padre. Por ejemplo (en tu CSS):

 #cropped { width: 100%; height: 80%; }
about 4 years ago · Juan Pablo Isaza Report

0

Bastante seguro de que esto es lo que quieres:

 div { border: 1px solid red; width: 200px; height: 200px; resize: both; overflow: hidden; } canvas { border: 1px solid blue; aspect-ratio: 1 / 1; box-sizing: border-box; max-width: 100%; max-height: 100%; margin: auto; }
 <div><canvas width="1000" height="1000"></canvas></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!