A field report with flexible media
How to fetch and submit this exercise
Once: install the tool and connect your account.
curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon loginEach exercise: download it, edit the file named in the instructions, then submit.
gonomicon fetch fs-week-1/06-05-field-report-responsive-media
cd 06-05-field-report-responsive-media
gonomicon submitGoal
Style .field-report__image so it shrinks to fit its container without stretching or distorting, and give .field-report__title a fluid font size that scales with the viewport but stays within fixed limits.
Example
A plain width: 100% forces an image to always fill its container — including growing past its own real size on a wide screen, which blurs it:
.bad-image {
width: 100%;
/* stretches to fill any container, even wider than the image really is */
}
max-width: 100% with height: auto only shrinks the image when its container is narrower than it is, and never grows it, while keeping its proportions:
.good-image {
max-width: 100%;
height: auto;
}
The same shrink-but-never-grow idea applies to text with clamp():
.fluid-title {
font-size: clamp(1.75rem, 4vw, 3rem);
/* never smaller than 1.75rem, never larger than 3rem, and scales
between them as the viewport width changes */
}
Rules
- Edit only
styles.css.index.htmlis already correct and must not change — it has one<img class="field-report__image">withalt,width,height,srcsetandsizesalready set, and one<h1 class="field-report__title">. .field-report__imageneedsmax-width: 100%andheight: auto— notwidth: 100%, which would force the image to always fill its container and can stretch it past its own real size..field-report__titleneedsfont-size: clamp(min, preferred, max), whereminandmaxareremvalues and the preferred value includes avwunit so the size actually changes with the viewport width, instead of jumping straight frommintomax.- Don't use flexbox, grid, media queries or container queries — this lesson is only about the box model's interaction with images, and about
clamp().
What you'll practice
Making an image responsive with max-width/height: auto instead of a plain width: 100%, and writing a clamp() font size that's genuinely fluid between a floor and a ceiling.
Run it
gonomicon fetch fs-week-1/06-05-field-report-responsive-media
cd 06-05-field-report-responsive-media
gonomicon test
gonomicon submit
Hints
- Give
.field-report__imagemax-width: 100%andheight: autoinstead ofwidth: 100%— that lets it shrink to fit a narrow container without ever stretching past its own size or losing its proportions. .field-report__title's font-size needsclamp(min, preferred, max), where the preferred value includes avwunit so it actually scales with the viewport — a fixed rem or px value in the middle isn't fluid..field-report__image { max-width: 100%; height: auto; } .field-report__title { font-size: clamp(1.75rem, 4vw, 3rem); }— nothing else needs to change.