I'm new to grids and I'm trying to understand some cell sizing concepts.
I have a container that is set to display: grid
and a main
element centered in the grid where the min-content
column/row is.
.main-container {
display: grid;
grid-template-columns: 1fr min-content 1fr;
grid-template-rows: 1fr min-content 1fr;
}
.main-container main {
grid-column: span 1
grid-column-start: 2
grid-row: span 1
grid-row-start: 2
}
canvas {
width: 800px;
height: 600px;
}
and html
<!-- page -->
<html>
...
<body>
<div class="main-container">
<main>
<canvas />
</main>
</div>
</body>
</html>
The application will center around the happenings of the canvas, and due to the nature of aspect ratios in canvas rendering, I want the center grid cell to conform to the size of the canvas and not the other way around.
I expect that due to both main
and canvas
being border-box
'ed and the size of the canvas being absolute, then the main
element should theoretically not effect the calculated min-content
height. this isn't the case for width but somehow the height adds 4 extra pixels.
Where did these extra height pixels come from and how can I ensure they don't appear
Setting the height of main explicitly to 600px does solve the problem, however this is redundant information and I anticipate there is a solution not involving hardcoded height bandaids.