Width and Height
width and height set the size of the content box (unless box-sizing changes that). Block elements are as wide as their parent by default; height follows the content. min-width, max-width, min-height and max-height set limits.
max-width is the friend of responsive design: width: 100%; max-width: 600px; lets a box shrink on small screens but never grow beyond 600px. Inline elements ignore width and height.
Example
<style>
.box {
width: 100%;
max-width: 320px;
min-height: 80px;
background: #ddd6fe;
padding: 12px;
}
</style>
<div class="box">Resize the preview. I never exceed 320px and never go below 80px tall.</div>Exercise
Never let the box grow past 500px.
.box { : 500px; }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.