Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda