I've encountered a problem while working with the grid layout using divs and flexbox. The header, which I want to be fixed, is overlapping with the first row and I'm struggling to get the scrolling behavior right. How can I address this issue? I thought about applying overflow-y: scroll only to the grid body, but that introduces an extra horizontal scrollbar.
var data = [{
"title": "Chicken Tortilla Soup!",
"youTubeId": "B7JUzPTib9A",
"rating": 0.9708955223880597,
...
}];
loadData();
function loadData() {
$(".gridBody").empty();
$.each(data, function(index, item) {
let row = $("<div>", {
class: "gridRow"
});
$.each(item, function(key, value) {
let cell = $("<div>", {
class: "gridCell",
text: value
});
$(row).append(cell);
});
$(".gridBody").append(row);
});
}
html,
body {
height: 100%;
}
#main {
height: 100%;
width: 80%;
margin: 0 auto;
}
.grid {
background-color: #fff;
display: flex;
flex-direction: column;
overflow-x: auto;
height: 80%;
}
.gridHeader {
height: 100px;
}
.gridBody {
overflow-y: scroll;
}
.gridHeader,
.gridRow {
display: flex;
}
.gridHeader .gridCell {
font-weight: bold;
}
.gridCell {
border: 1px solid #000;
min-width: calc(100% / 6);
padding: 10px;
word-break: break-word;
text-align: center;
}