Here is div at minimum height without content
Its height can be expanded by content
When it reach max-height need to show scroll, and content become scrollable
CodePudding user response:
Please, Check this code
#content {
position: relative;
min-height: 20px;
background-color: green;
max-height: 200px;
overflow: auto;
}
<html>
<head>
<meta charset="UTF-8" />
<script src="script.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="content">
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
</div>
</body>
</html>
Demo Link: https://stackblitz.com/edit/web-platform-g3xn1g?file=styles.css