Card Media Frames
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 12 of 55.
A media frame has two decisions: its box shape and the way the source image fits inside that shape. aspect-video creates a 16:9 box; aspect-square creates a 1:1 box. Give the image a width so the browser can calculate its height.
<img src="provided-photo.svg" alt="Paintbrushes on a desk" class="w-full aspect-video object-cover object-center">The worked example displays a 16:9 cover-cropped image. object-cover preserves source proportions while filling the box, so some pixels may be cropped. object-contain preserves the whole source but can leave unused space; object-fill can distort it.
Choose the focal alignment independently. object-center centers both axes and object-top aligns top center. Keep meaningful alternative text and consider whether cropping hides important information.
Challenge
MediumMake the supplied card image a square, centered, cover-cropped preview filling its 240px card width. Preserve the image and descriptive alternative text.
Preserve the supplied content, semantic elements and IDs. Edit the requested utility classes. Press Run preview after edits, then Check/Run code to grade the result. Supplied JavaScript is read-only.
Try it yourself
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Interface workshop</title><link rel="stylesheet" href="./styles.css"></head><body>
<article class="w-60"><img id="photo" alt="Grid illustration with an orange circle at the top and colored shapes below" src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22600%22%20height%3D%22300%22%20viewBox%3D%220%200%20600%20300%22%3E%3Crect%20width%3D%22600%22%20height%3D%22300%22%20fill%3D%22%23dbeafe%22%2F%3E%3Cpath%20d%3D%22M0%20100H600M0%20200H600M0%20300H600M0%20400H600M0%20500H600M100%200V300M200%200V300M300%200V300M400%200V300M500%200V300%22%20stroke%3D%22%2364748b%22%20stroke-width%3D%224%22%2F%3E%3Ccircle%20cx%3D%2280%22%20cy%3D%2265%22%20r%3D%2240%22%20fill%3D%22%23f97316%22%2F%3E%3Crect%20x%3D%22180%22%20y%3D%22200%22%20width%3D%2290%22%20height%3D%2270%22%20fill%3D%22%234338ca%22%2F%3E%3Cpath%20d%3D%22M20%20280L90%20160L150%20280Z%22%20fill%3D%22%2315803d%22%2F%3E%3C%2Fsvg%3E" class="w-full aspect-auto object-fill"><h2>Workshop</h2></article>
</body></html>
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Responsive UI Patterns
1Page Shells
Growing Page ShellsFlexible Content RailsBounded Scroll RegionsFull-Bleed RegionsRecap: Page Shells4Form Layouts
Responsive Field GroupsFocused Field GroupsSelectable Form OptionsNative Validation CuesRecap: Form Layouts2Navigation Patterns
Wrapping NavigationCurrent Page CuesNative Menu DisclosuresKeyboard Skip LinksRecap: Navigation5Data Tables
Scrollable Data TablesPredictable Table ColumnsRow State PresentationSticky Table HeadersRecap: Data Tables8Interactive Panels
Expanded Control CuesChoice Card StatesFocus-Aware Help PanelsContent-Aware Empty StatesRecap: Interactive Panels11Project: Event Portal
Portal ShellSession Browser3Content Cards
Aligned Card ActionsCard Media FramesResponsive Feature CardsShared Card RowsRecap: Content Cards