About Lesson
max-height and min-height:
Definition:
max-height
sets the maximum height an element can grow to.min-height
sets the minimum height an element must be, even if its content is smaller.
Syntax:
selector {
max-height: value;
min-height: value;
}
/*value can be in units like px, %, em, rem, etc.*/
Example:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.tall-box {
min-height: 100px;
max-height: 200px;
background-color: lightcoral;
border: 2px solid maroon;
overflow: auto;
padding: 10px;
margin: 20px;
}
</style>
<title>Max and Min Height Example</title>
</head>
<body>
<div class="tall-box">
This box has a minimum height of 100px and a maximum height of 200px. If the content exceeds 200px, scroll will appear.
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla commodo, nisi at fringilla convallis, mauris justo porta orci, vitae pulvinar velit velit sed justo.</p>
<p>Additional content to exceed max-height.</p>
</div>
</body>
</html>