html {
height: 100%;
}
body {
min-height: 100vh;
min-height: -webkit-fill-available;/*only thing so far that makes the footer section visible */
width: 100%;
margin: 0;
padding: 0;
position: fixed;
}
.main-container {
width: 100%;
height: 100%;
flex: 1;
overflow: hidden;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.content-section {
overflow-x: scroll;
flex: 1;
padding: 0;
margin: 0;
}
table.table {
table-layout: fixed;
min-width: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no viewport-fit=cover">
<title>Document</title>
</head>
<body>
<div class="main-container">
<div class="header-section"></div>
<div class="content-section">
<table class="table">
</table>
</div>
<div class="footer-section"></div>
</div>
</body>
</html>
Here is my layout
- Container DIV -- Header Section --Content Section --Footer Section (containing a toolbar)
Container DIV is set to display flex - Column. Content section is set to flex 1. Header and Content sections are sized by their content and padding.
Content Section contains a table with dynamically generated content with varying number of rows.
The table needs to fit exactly between the header and footer with no vertical scrolling. I wrote a function to get the height of the content div, and then set the height of the table cell based on the number of rows resulting from the dynamic content.
The method I use seems a bit crude to me, and I wondering if there is a better, elegant, more professional way to do this. I am also interested in being able to pause or load a spinner while the dimensions of the content section div is determined by the JavaScript code.
EDIT: JavaScript included:
function setDimensions () {
const main = document.querySelector('.content-section');
const theight = main.getBoundingClientRect().height;
const rows = Array.from(document.querySelectorAll('tr'));
const rowCount = rows.length;
const heightWidth = theight / rowCount;
rows.forEach(row => {
let cheight = 0;
cheight = `${heightWidth}px`;
row.style.height = cheight;
Array.from(row.cells).forEach(cell => {
if(cell.cellIndex === 0) cheight = `${heightWidth*2.295}px`;
else if(cell.classList.contains('sum')) cheight = `${heightWidth*1.25}px`
else cheight = `${heightWidth}px`;
cell.style.width = cheight;
})
})
}
Thank you.