Bounded Fluid Components
Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 29 of 55.
Container-relative units can scale part of a component continuously rather than switching at a breakpoint. One cqw is one percent of the eligible query container’s width. The example makes a divider 30% of that width.
<section class="@container"><div class="w-[30cqw] h-1 bg-black" aria-hidden="true"></div></section>For text, use clamp(minimum,preferred,maximum) to retain readable bounds. For example, text-[clamp(14px,3cqw,26px)] grows with the container but never goes below 14px or above 26px. Commas keep this expression inside one arbitrary utility.
A fluid unit and a query threshold solve different problems. Use thresholds for discrete layout changes and bounded fluid values for gradual sizing. Always establish the intended container so the size source is explicit.
Challenge
MediumMake the bulletin heading use a fluid size of 5% of its query container width, with a minimum of 16px and maximum of 32px. Preserve the heading element and verify the supplied host widths of 320px, 480px and 800px.
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>
<section id="host" class="@container w-[320px]"><h2 id="title" class="text-base">Studio bulletin</h2></section><button id="size480" class="m-2">Width 480</button><button id="size800" class="m-2">Width 800</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