P粉4589136552023-09-04 16:01:19
You have aspect-ratio
telling the board to have the same height as the width, so if your width is 3000px, your height will be the same. You have a choice
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; } .parent { height: 100vh; background-color: grey; display: flex; flex-direction: column; } .header { flex-shrink: 0; height: 10px; background-color: blue; } .child { flex-grow: 1; background-color: lightcoral; } .chessboard { height: 100%; max-height: 100%; background-color: purple; margin: auto; } .footer { flex-shrink: 0; height: 10px; background-color: green; }
<div class="parent"> <header class="header"> </header> <div class="child"> <div class="chessboard"> main </div> </div> <footer class="footer"> </footer> </div>
P粉0345716232023-09-04 15:38:58
The final answer depends on some clarification on your part. I asked you in a comment on this question. But I will give a general answer.
I will briefly explain what is done in the example below.
I created a .chessboard-wrapper
with a in it.
Scale as needed, with
aspect-ratio: 1;
.
.chessboard
itself has position:absolute;
and will take the dimensions of the parent.
* { margin: 0; padding: 0; box-sizing: border-box; } .parent { height: 100vh; background-color: grey; display: flex; flex-direction: column; } .header { height: 10px; background-color: blue; flex: none; } .child { background-color: red; flex: auto; min-height: 0; display: flex; flex-direction: column; } .chessboard-wrapper { position: relative; min-height: 0; margin: auto; aspect-ratio: 1; } .chessboard-wrapper > canvas { max-width: 100%; max-height: 100%; } .chessboard { position: absolute; inset: 0; background-color: purple; } .footer { height: 10px; background-color: green; flex: none; }
<div class="parent"> <div class="header"></div> <div class="child"> <div class="chessboard-wrapper"> <canvas width="1000000" height="1000000"></canvas> <div class="chessboard"></div> </div> </div> <div class="footer"></div> </div>