How do i prevent a div with a dynamically sized list growing too large? when the number of items in the list is small, the div is correctly sized, but when i add more items, the div containing the list grows even though it has overflow: auto on it.
If you copy in more list items in this jsfiddle https://jsfiddle.net/kdqajmt1/106/ the outer page wrapper begins to also scroll, which i dont want.
html, body{
padding:0;
margin:0;
height:100%;
}
header {
text-align:center;
position: fixed;
width: 100%;
border: 1px black solid;
height: 30px;
}
.wrapper {
height: 100%;
width: 100%;
border: 1px red solid;
padding-top: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
h3 {
margin-right: 20px;
}
.list-container {
display: flex;
flex-direction: column;
padding: 20px;
width: 50%;
height: 100%;
}
.list {
height: 100%;
overflow-y: auto;
overflow-x: hidden;
border: 1px black solid;
}
<header>header</header>
<div class="wrapper">
<h3>my list</h3>
<div class="list-container">
other stuff
<div class="list">
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
</div>
</div>
<div class="btn-wrapper">
<button>
btn1
</button>
<button>btn2</button>
</div>
</div>
2
Answers
To prevent your
div
from growing too large, you can setmaxHeight
onlist
class.For example:
you need set postion .