topskill.dev
CoursesTracks
0
All courses/CSSImages that fit
Responsive Design
5 / 6
← CSS
○CSS Rule Style an Exhibit Card○Write Your First CSS Rule○CSS Selectors Target Exhibit Details○Target Exhibit Details○Apply CSS Three Sources○Apply CSS Three Ways○Specificity Resolve a Style Conflict○Resolve Specificity○Inheritance and the cascade✦Module Quiz
○Color Palette○Color Palette○Background Layer○Background Layer○Type Rhythm○Type Rhythm○Borders and Shadows○Borders and Shadows✦Module Quiz
○Box Model Seed Packet Card○Space a Seed Packet○Display Swap Table Labels○Arrange Swap Table Labels○Positioning Pickup Pin○Pin the Pickup Location○Sizing and Overflow○Size a Seed-Swap Notice○Sticky scroll headings✦Module Quiz
○Advanced Selectors Book Cart Sign○Target a Book Cart Sign○Pseudo-Classes Night Cart States○Style Night Cart States○Pseudo-Elements○Add a Book-Quote Mark✦Module Quiz
○Lantern Market navigation○Lantern Market navigation✦Module Quiz
○Community garden request card○Community garden request card✦Module Quiz
○Flex Direction○Flex Direction○Main-Axis Spacing○Main-Axis Spacing○Cross-Axis Alignment○Cross-Axis Alignment○Wrapping and Flex Items○Wrapping and Flex Items○Flexbox Navigation○Flexbox Navigation✦Module Quiz
○Grid Tracks○Grid Tracks○Grid Gaps○Grid Gaps○Grid Placement○Grid Placement○Responsive Grid○Responsive Grid✦Module Quiz
○River radio schedule○Harbor radio schedule✦Module Quiz
○Field note color system○Field note color system○Transforms○Rotate a Field Note○Resilient styles✦Module Quiz
○Kite festival signal○Garden festival signal✦Module Quiz
○Garden forecast○Harbor forecast○Fluid sizing○Fluid weather bulletin●Images that fit✦Module Quiz
○Seed inventory table○Tool checkout table✦Module Quiz
○Community maker profile○Maker profile sheet✦Module Quiz

Images that fit

Fit the picture without stretching it

A flexible grid does not automatically resize an image with a large intrinsic width. This card supplies an 800-by-400 illustration. The circles make distortion easy to spot; both image files are embedded in the page, so the experiment does not depend on a remote photo.

max-width: 100% caps an image at its containing block’s width without making a smaller natural image grow unnecessarily. height: auto lets the browser calculate the height from its aspect ratio. Together, these rules preserve the full picture while allowing it to shrink. The HTML width and height attributes remain useful size/aspect-ratio hints; the CSS controls the final rendered size here.

A thumbnail has a different job. Its supplied CSS fixes both dimensions to 8rem, a square. object-fit: cover fills that square while preserving the artwork’s proportions, so some of the image is cropped. object-fit: contain would keep the whole artwork inside the square and may leave empty space. Neither changes the size of the image element’s box. Keep meaningful alternative text in HTML; CSS cropping does not choose a new alternative for you.

Your Task

  1. Set .landscape to max-width: 100% so it cannot extend beyond its card.
  2. Set .landscape to height: auto so its two-to-one aspect ratio survives resizing.
  3. Set .thumbnail to object-fit: cover to fill its supplied square without stretching the artwork.

Edit style.css, Run, and compare narrow and wide previews. After step 1 alone the full-width picture may look squashed because its fixed height is still present; step 2 restores its proportions. The thumbnail is intentionally cropped, not another example of showing the whole image. Submit checks each decision. HTML’s srcset and picture can select different resources, but that is a separate asset-delivery decision, not a replacement for CSS sizing.

Take the Quiz →
Files
  • ⋄index.html
  • ⋄style.css
Loading editor…