Named Query Regions
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 28 of 55.
Nested components can introduce several possible query ancestors. Name a container when a descendant must respond to a particular region rather than simply the nearest eligible container. @container/sidebar creates an inline-size container named sidebar.
<aside class="@container/sidebar"><div class="@container"><p class="hidden @min-[420px]/sidebar:block">Sidebar details</p></div></aside>The example uses @min-[420px]/sidebar: to target that named region. The slash name belongs to the variant before the utility. A nearer unnamed container does not replace the requested named ancestor.
Names are useful for components embedded inside other components. Keep them meaningful and local to the layout role. Repeated copies may share the same name because each descendant resolves its own ancestor chain.
Challenge
MediumName the 600px outer section panel and make it an inline-size query container. The card is hidden by default, but must display as a block when the named panel reaches 500px. Its nearer unnamed 240px container must not control this decision.
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.
Use the supplied controls to narrow the named panel to 400px and widen it to 600px again. The summary must hide below its threshold and reappear above it while the nearer unnamed container stays 240px wide.
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>
<section id="outer" class="w-[600px] "><div class="@container w-[240px]"><div id="card" class="hidden">Panel summary</div></div></section>
<button id="narrow">Narrow panel</button><button id="wide">Wide panel</button><script src="./controls.js"></script></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 Queries