I have a page containg a panel on the left and right side. The right side represents a list of items and it might be that this list gets larger than the page height. If that happens, I don't want to scroll the whole page, I only want to scroll this list container. I thought overflow-y: scroll;
would do the trick so I created this
$(document).ready(() => {
for (let i = 0; i < 100; i++) {
const newDiv = (`<div>Log Item</div>`);
$("#logsContainer").append(newDiv);
}
});
#page {
display: grid;
grid-template-columns: 50% 50%;
}
#logsContainer {
overflow-y: scroll;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="page">
<div>
Commands
</div>
<div>
<div>
Logs
</div>
<div id="logsContainer">
</div>
</div>
</div>
Unfortunately it still creates a scrollbar for the whole page and I can't scroll within the div. How can I create a scrollbar for that list only if the items in the list are too many to display?