Bounded Component States
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 27 of 55.
Sometimes a component needs a special layout only in an intermediate width range. Stack a minimum and maximum container variant on the same utility. The minimum is inclusive, while the maximum uses a strict less-than boundary.
<div class="@container"><div class="hidden @min-[300px]:@max-[500px]:flex">Compact actions</div></div>The example shows a compact action row from 300px up to, but not including, 500px. Outside that interval the base display remains in effect. This is a deliberate presentation policy, not a rule that wider always means more visible.
Write down both boundaries before choosing classes. Check the exact boundary values as well as nearby widths. A minimum-only implementation can look right in the middle and still fail when the component becomes larger.
Challenge
MediumKeep the tools in a vertical flex stack by default. Only while the supplied host is at least 320px and less than 480px wide, use a horizontal row. Keep 8px gaps on both axes at every size and preserve both links.
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>
<div id="host" class="@container w-[300px]"><nav id="tools" aria-label="Tools" class="flex flex-col gap-2"><a href="#edit">Edit</a><a href="#share">Share</a></nav></div><button id="size320" class="m-2">Width 320</button><button id="size479" class="m-2">Width 479</button><button id="size480" class="m-2">Width 480</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