Menu
CoddyTech

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 icon

Challenge

Medium

Make 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>
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