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

264
Views
Is there a way to force a canvas to rescale with only height not width?

Im building a website where a graph is drawn on a canvas within a div that can be resized. Whenever i resize the div the canvas also resizes to fit the whole width of the div, however this leaves alot of empty space above and below which is not great looking, id rather the canvas fit the whole height then clip beyond the end of the div meaning that the user could scale the graph to their liking without the empty space above and below.

Is there a way to force the canvas to scale with height?

Here is the HTML elements that make up the graph:

<div class='graphHolder' id='graphHolder1'>
    <div class='graph' id='graph1'>

        <canvas class='chart' id='chart' height='100%'></canvas>
                
    </div>
</div>

And here is the CSS for those elements:

.graphHolder {
    width: 300px;
    height: 150px;
    position: absolute;
    top: 50px;
    left: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.3);
    overflow: hidden;
    resize: both;
    border: 1px solid #d62828;
    border-radius: 10px;
}

.graph{
    width: -moz-calc(100% - 5px);
    width: -webkit-calc(100% - 5px);
    width: calc(100% - 5px);
    height: -moz-calc(100% - 5px);
    height: -webkit-calc(100% - 5px);
    height: calc(100% - 5px);
    background: ;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chart {
    width: calc(100% - 5px);
    height: calc(100% - 5px);
    background: white;
    border: ;
}
about 4 years ago · Juan Pablo Isaza
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!