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
MediumAnchor 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>
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 Cards6Container Queries
Component Width QueriesBounded Component StatesNamed Query RegionsBounded Fluid ComponentsRecap: Container Queries9Layered Surfaces
Anchored Card BadgesLocal Layer BoundariesNonblocking DecorationResponsive Sticky RailsRecap: Layered Surfaces