I'm trying to achieve the following layout:
- Top bar
- Main content placeholder
- Bottom bar
The main content has (always one at the same time though) children, one of which is a table which should always be square.
How can I do this with CSS? I've tried flexbox and CSS grid including aspect-ratio but couldn't get it to work.
The idea is basically the following:
- Top/Main content/Bottom is always the same height/full width
- If there's a table inside the main content, it should be square. The main content placeholder should remain the size but the table within should always be automatically resized to be square (ideally with the minimum of available width or height)
- To achieve this, it's okay for the top bar the change its height, the bottom bar should remain fixed
Here's some example code I've tried:
<!DOCTYPE html>
<html lang="en" style="height: 100%;">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
.main {
background: gray;
height: 100vh;
grid-template-rows: 20% 60% 20%;
display: grid;
}
.top {
background: red;
}
.placeholder {
background: green;
width: 100%;
height: 100%;
position: relative;
}
.square-table {
background: yellow;
aspect-ratio: 1/1;
height: 100%;
position: absolute;
}
.bottom {
background: blue;
}
</style>
</head>
<body style="height: 100%;">
<div class="main">
<div class="top">Top</div>
<div class="placeholder">
<p>Generic placeholder</p>
<table class="square-table">
<tbody>
<tr>
<td>abc</td>
</tr>
</tbody>
</table>
</div>
<div class="bottom">Bottom</div>
</div>
</body>
</html>
Any help or pointers in the right direction would be much appreciated.