TL;DR: here is a full page example: https://jsfiddle.net/rfp8xv6g/show (editable here: https://jsfiddle.net/rfp8xv6g), how to make that the canvas (with purple border) is fully contained vertically in the container, without hardcoding a height?
Here is a simplified example. I have the following layout (click "Full page" in the snippet to be able to see it).
The left column contains a wrapper containing several <canvas>
on top of each other (here only one canvas for simplicity).
Problem: if the canvas width/height is high (in canvas coordinate system, here 4000x3000), then the full canvas is not visible (too high in height, it grows out of the viewport).
How to make that the canvas is scaled/shrinked to be contained in the left column? (without a page vertical scrollbar)
Here max-width: 100%;
works in order to have the canvas contained horizontally.
But max-height: 100%;
doesn't do any effect: the canvas is not contained vertically, why?
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html,
body,
.page {
height: 100%;
width: 100%;
}
.page {
background-color: red;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.left-column {
background-color: green;
display: flex;
}
.right-column {
background-color: orange;
flex: 1;
}
canvas {
border: 3px solid magenta;
max-width: 100%;
max-height: 100%;
}
<div class="page">
<div class="left-column">
<div class="canvas-wrapper">
<canvas width="4000" height="3000"></canvas>
</div>
</div>
<div class="right-column">
RIGHT
</div>
</div>