const container = document.querySelector('.container');
const tbody = document.querySelector('#myTable tbody');
const ROW_COUNT = 40;
for (let i = 1; i <= ROW_COUNT; i++) {
const tr = document.createElement('tr');
const td = document.createElement('td');
td.textContent = 'Row ' + i;
tr.appendChild(td);
tbody.appendChild(tr);
}
function updateRowHeights() {
const rows = tbody.querySelectorAll('tr');
const totalHeight = container.clientHeight;
const rowHeight = totalHeight / rows.length;
rows.forEach(row => {
row.style.height = rowHeight + 'px';
});
}
updateRowHeights();
window.addEventListener('resize', updateRowHeights);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
height: 50vh;
width: 90vw;
margin: 2rem auto;
border: 2px solid #666;
overflow: hidden;
}
table {
width: 100%;
border-collapse: collapse;
}
td {
border: 1px solid #999;
text-align: center;
}
<div class="container">
<table id="myTable">
<tbody></tbody>
</table>
</div>
This is just a sample code of what I’m trying to do in my project(for reference of what I’m talking about).
I need a div to fit dynamically to the screen(the HTML need to be able to be opened in normal PC monitor, TV, tablets, and mobile), in here i make the container 50vh.
The problem is I have a table with decent rows(about 40-50). I need them to be displayed entirely, no matter the size of the font or rows(it doesn’t matter if its so small), inside the table without any scrolling or paging(my company needs to cut cycle time of production).
I have not found a way to do this, its either getting cut off vertically, hidden by overflow:hidden, or the scrollbar show-up. Any help would be nice !