About Lesson
max-width and min-width:
Definition:
max-width
sets the maximum width an element can expand to.min-width
sets the minimum width an element must be, even if the screen is small.
Syntax:
selector {
max-width: value;
min-width: 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>
.wide-box {
min-width: 150px;
max-width: 400px;
background-color: lightyellow;
border: 2px solid orange;
padding: 10px;
margin: 20px auto;
}
</style>
<title>Max and Min Width Example</title>
</head>
<body>
<div class="wide-box">
This box has a minimum width of 150px and a maximum width of 400px. Resize the browser window to see the effect.
</div>
</body>
</html>