A product preview card is one of the most common pieces of an online shop: a photo, a short pitch, the price and a button. It looks simple, but getting it right means a layout that flips from stacked to side by side, an image that crops instead of stretching, and a few small accessibility details that are easy to forget.
You are given the markup for one card. Write only CSS in styles.css (no JavaScript, and no changes to the HTML) so that the card meets these requirements.
Layout
.card is at most 600px wide and centered horizontally. It has rounded corners, and the image corners are rounded with it (nothing pokes out of the card).600px, the image sits on top and the text content below it. The image takes the full width of the card and is exactly 240px tall.600px up, the card has two equal columns: the image on the left and the text content on the right. The image fills the full height of the card..product-image, set in the provided styles. The element has role="img" and an aria-label, so screen readers still announce it. In both layouts the photo must cover its whole box, stay centered and keep its proportions: cropped to fit, never squashed, stretched or tiled..content area has inner padding, and its items are spaced evenly.≥ 600px < 600px ┌──────────────┬──────────────┐ ┌──────────────┐ │ │ KITCHEN │ │ image │ 240px │ │ Title │ ├──────────────┤ │ image │ Description │ │ KITCHEN │ │ │ $64.00 $80 │ │ Title │ │ │ [Add to cart]│ │ ... │ └──────────────┴──────────────┘ └──────────────┘
Details
.category) is shown in uppercase with extra letter spacing. Do this in CSS, since the text in the HTML stays as written for screen readers..visually-hidden class that hides it on screen but keeps it in the accessibility tree. display: none and visibility: hidden don't count, because they hide it from screen readers too.48px tall so it is easy to tap, and has rounded corners.2px) when it is reached with the keyboard. Use :focus-visible so the ring doesn't show on mouse clicks.The colors and typography are already provided, so you can focus on the layout and the details above.
Credit: the idea comes from the Frontend Mentor challenge Product preview card component. This version uses its own markup, content and requirements.
≥ 600px < 600px
┌──────────────┬──────────────┐ ┌──────────────┐
│ │ KITCHEN │ │ image │ 240px
│ │ Title │ ├──────────────┤
│ image │ Description │ │ KITCHEN │
│ │ $64.00 $80 │ │ Title │
│ │ [Add to cart]│ │ ... │
└──────────────┴──────────────┘ └──────────────┘