The issue is, I can’t figure out how to make the top and bottom padding work so that the scrollable content won’t touch the top and bottom borders when scrolling.
I’ve tried several methods I can think of, such as adding an outside container element, but didn’t work. Also tried the opposite of adding container inside.
Here’s the code in question:
<style>
.container {
height: 100px;
width: 300px;
overflow-y: scroll;
padding: 10px;
background-color: black;
color: white;
}
</style>
<div class="container">
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
<li>dogs</li>
</div>
I simply want to add a padding there that will prevent the content touching border.
Any ideas would be really appreciated! Thank you!
3
Answers
Okay I think I just figured out the answer. I'm just not sure if it's the right one. The trick is to add either an external or internal container, then adjust the CSS accordingly. What's important is setting a different height for the container that has the content.
It's something like this:
If I understand you correctly, you can try using pseudo-elements with
display: sticky
as indents.Example below:
A simple solution would be to use a matching
border
instead ofpadding
(or in addition to it).