Menu
CoddyTech

Anchored Card Badges

Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 41 of 55.

A small status badge can sit over a card surface without becoming a separate layout row. Give the card relative positioning and its badge absolute. The card then provides the containing block for the badge’s edge offsets.

<article class="relative pt-10"><span class="absolute top-2 right-2">Featured</span><h2>Evening studio</h2></article>

The example places a badge 8px from the top and right. Absolute children do not consume normal-flow space, so the card reserves top padding for its heading. Relative positioning without offsets keeps the card in its ordinary page position.

Treat the badge as supplemental information and preserve the card heading. Choose both vertical and horizontal insets intentionally. With multiple badges, ensure each has its own placement and enough room around the primary content.

challenge icon

Challenge

Medium

Anchor the New badge to the supplied card, 12px from both its top and right edges. Use absolute positioning for the badge and relative positioning for the card. Preserve the supplied 48px top padding so the heading stays below the badge region.

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 id="card" class="w-80 h-40 pt-12 static"><span id="badge" class="static">New</span><h2>Studio tour</h2></article>
</body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Responsive UI Patterns