A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
<style>img { display:block; width:100%; height:auto; }</style><main class="demo"><div aria-label="Example media" class="media-placeholder" role="img">Media example</div></main>
Engineering judgment: Separate image sizing from image fitting. First decide the box; then decide whether the media should cover or contain it.
<style>.avatar { width:8rem; aspect-ratio:1; object-fit:cover; }</style><main class="avatar">Example content</main>
In production, object-fit only affects replaced elements when there is a concrete content box to fit into. Giving an image width without a usable height often leaves the intrinsic ratio doing the work instead. That is the kind of bug that survives visual spot checks because the stylesheet is syntactically valid while the layout contract is wrong.
| Concern | What to inspect | Typical failure |
|---|---|---|
| Core behavior | Responsive Images and Containers | object-fit only affects replaced elements when there is a concrete content box to fit into. Giving an image width without a usable height often leaves the intrinsic ratio doing the work instead. |
| Production test | Real content and constraints | The rule works only for the demo values |
| Maintenance | Scope and override path | A later fix creates another exception |
The useful mental model here is practical: how replaced elements, object fitting, intrinsic ratios, and max-width constraints prevent media from breaking layout. When a rule looks obvious but the browser produces something else, start by identifying which constraint or rendering phase is actually winning.
A good CSS change narrows the problem. Separate image sizing from image fitting. First decide the box; then decide whether the media should cover or contain it. This keeps the rule understandable when content, theme, or viewport conditions change later.
<style>.logo { object-fit:contain; }</style><main class="logo">Example content</main>
Contain illustration is useful here because it demonstrates responsive images and containers under a concrete input rather than as an abstract property list.
<style>.media { max-width:100%; }</style><main class="media">Example content</main>
Container cap is useful here because it demonstrates responsive images and containers under a concrete input rather than as an abstract property list.
Finish the lesson once you have worked through the material. This awards ★ 30 XP.