Flex 확장, 축소 및 기준 크기
flex-1, flex-none, grow, shrink, basis-* 유틸리티를 사용해 플렉스 자식 요소가 확장되거나 축소되는 방식을 조절합니다.
Flex 확장, 축소 및 기준 크기은(는) CoddyKit의 무료 Tailwind CSS Academy 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Tailwind CSS Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
How Flex Children Size Themselves
By default, flex children are sized according to their content. But Flexbox provides three properties that give you fine control over how children fill available space: flex-grow controls how much extra space a child claims, flex-shrink controls how much it compresses when space is tight, and flex-basis sets the initial size before growing or shrinking. Tailwind exposes all three with concise utility classes.
flex-1: The All-In-One Shorthand
flex-1 is the most commonly used flex sizing utility. It applies flex: 1 1 0% — grow to fill available space, shrink when necessary, and start from a zero basis. In practice, flex-1 makes each item claim an equal share of the remaining container space. Two flex-1 siblings each take 50%; three take 33% each.
<!-- Two equal-width columns -->
<div class="flex gap-4">
<div class="flex-1 bg-blue-100 p-4 rounded">Left (50%)</div>
<div class="flex-1 bg-green-100 p-4 rounded">Right (50%)</div>
</div>
<!-- Three equal-width columns -->
<div class="flex gap-4 mt-4">
<div class="flex-1 bg-indigo-100 p-4 rounded">A (33%)</div>
<div class="flex-1 bg-indigo-200 p-4 rounded">B (33%)</div>
<div class="flex-1 bg-indigo-300 p-4 rounded">C (33%)</div>
</div>flex-auto: Content-Aware Growth
flex-auto applies flex: 1 1 auto — it grows and shrinks but starts from the element's natural content size. Unlike flex-1 which starts from zero, flex-auto preserves the size difference between items before distributing extra space proportionally. Use it when you want content-aware distribution rather than equal splits.
<!-- flex-auto: longer text gets more space -->
<div class="flex gap-2">
<div class="flex-auto bg-blue-100 p-4 rounded">Short</div>
<div class="flex-auto bg-green-100 p-4 rounded">Longer text content item</div>
</div>
<!-- flex-1: equal splits regardless of content -->
<div class="flex gap-2 mt-2">
<div class="flex-1 bg-blue-100 p-4 rounded">Short</div>
<div class="flex-1 bg-green-100 p-4 rounded">Longer text content item</div>
</div>flex-initial: Default Browser Behavior
flex-initial applies flex: 0 1 auto — the browser default. Items do not grow beyond their content size (grow: 0), but they will shrink if space is tight (shrink: 1). This is used to explicitly state the default in a context where sibling items use flex-1, keeping the initial item sized to its content while siblings take up remaining space.
<!-- Sidebar fixed to content, main area takes remaining space -->
<div class="flex gap-4">
<aside class="flex-initial w-48 bg-gray-100 p-4 rounded">
Fixed sidebar
</aside>
<main class="flex-1 bg-white p-4 rounded shadow">
Main content takes all remaining width
</main>
</div>flex-none: Prevent All Sizing Changes
flex-none applies flex: none — the item will neither grow to fill extra space nor shrink when space is limited. The item always remains exactly its natural content size. Use flex-none for icons, avatars, badges, and fixed-width elements that should maintain their size regardless of how much space is available in the flex container.
<!-- Avatar should stay fixed size, text can shrink/grow -->
<div class="flex items-center gap-3">
<img src="avatar.jpg" class="flex-none w-12 h-12 rounded-full" alt="" />
<div class="flex-1 min-w-0">
<p class="font-medium text-gray-900 truncate">User name that might be very long</p>
<p class="text-sm text-gray-500 truncate">user@example.com</p>
</div>
<span class="flex-none bg-green-100 text-green-700 text-xs px-2 py-1 rounded">Active</span>
</div>grow and shrink Utilities
For fine-grained control, Tailwind provides separate grow, grow-0, shrink, and shrink-0 utilities. grow allows the item to grow (flex-grow: 1). grow-0 prevents growth. shrink allows shrinking (flex-shrink: 1). shrink-0 prevents shrinking — useful for preventing images and icons from being compressed when the container is too narrow.
<!-- Logo should not shrink on small screens -->
<nav class="flex items-center gap-4">
<img src="logo.svg" class="shrink-0 h-8 w-auto" alt="Logo" />
<!-- Nav links can shrink -->
<div class="flex gap-4 min-w-0">
<a href="#" class="truncate text-sm">Products</a>
<a href="#" class="truncate text-sm">Pricing</a>
</div>
</nav>basis-*: Setting the Starting Size
basis-* sets the initial size of a flex item before growing or shrinking. It maps to CSS flex-basis. You can use Tailwind spacing values (basis-4 = 16px), percentage values (basis-1/2 = 50%), or keyword values (basis-full = 100%). Setting basis-1/3 on three siblings with grow creates a three-column layout that starts at equal thirds and fills available space.
<!-- Three columns with basis -->
<div class="flex gap-4">
<div class="basis-1/3 grow bg-blue-100 p-4 rounded">A (starts at 33%)</div>
<div class="basis-1/3 grow bg-green-100 p-4 rounded">B (starts at 33%)</div>
<div class="basis-1/3 grow bg-red-100 p-4 rounded">C (starts at 33%)</div>
</div>basis-0 vs basis-auto
basis-0 and basis-auto produce subtly different results when combined with grow. With basis-0, all items start at zero width and grow purely based on their flex-grow ratios — resulting in equal space allocation. With basis-auto, items first claim their content width, then extra space is distributed — resulting in content-proportional allocation.
/* flex-1 = flex: 1 1 0% → basis-0 + grow + shrink */
/* flex-auto = flex: 1 1 auto → basis-auto + grow + shrink */
<!-- These produce different column widths when content differs:
flex-1: equal columns
flex-auto: content-proportional columns -->Practical: Main Content + Fixed Sidebar
A classic two-panel layout uses flex-none w-64 on the sidebar (fixed 256px width) and flex-1 on the main content area (takes everything else). This creates a sidebar that never grows or shrinks combined with a content area that fills 100% of remaining space. It is the foundation of dashboard and admin UI layouts.
<div class="flex h-screen">
<aside class="flex-none w-64 bg-gray-900 text-white p-4">
<h2 class="font-bold text-lg mb-4">Sidebar</h2>
<nav class="space-y-1">
<a href="#" class="block px-3 py-2 rounded hover:bg-gray-700 text-sm">Dashboard</a>
</nav>
</aside>
<main class="flex-1 overflow-auto bg-gray-50 p-8">
<h1 class="text-2xl font-bold text-gray-900">Dashboard</h1>
</main>
</div>Practical: Responsive Grid Cards With flex-1
Combining flex flex-wrap with flex-1 and a min-w-* constraint creates a responsive grid that automatically adjusts the number of columns based on available width. Each card takes at least min-w-64 width, and they expand to fill the row with flex-1. When a card cannot fit, it wraps to the next line — no explicit breakpoint management needed.
<!-- Auto-responsive card grid -->
<div class="flex flex-wrap gap-4">
<div class="flex-1 min-w-64 bg-white rounded-xl shadow p-6">
<h3 class="font-bold">Card A</h3>
</div>
<div class="flex-1 min-w-64 bg-white rounded-xl shadow p-6">
<h3 class="font-bold">Card B</h3>
</div>
<div class="flex-1 min-w-64 bg-white rounded-xl shadow p-6">
<h3 class="font-bold">Card C</h3>
</div>
</div>Order: Rearranging Visually
Tailwind's order-* utilities change the visual display order of flex items without changing their DOM order. order-first moves an item to the beginning, order-last moves it to the end, and order-1 through order-12 provide granular control. This is useful for responsive reordering: a sidebar that appears after content on mobile can be moved visually before it on desktop with md:order-first.
<!-- Mobile: image below text. Desktop: image on the right -->
<div class="flex flex-col md:flex-row gap-8">
<div class="md:order-last flex-1">
<img src="product.jpg" class="w-full rounded-xl" alt="" />
</div>
<div class="flex-1">
<h2 class="text-2xl font-bold">Product Headline</h2>
<p class="text-gray-500 mt-2">Description text here.</p>
</div>
</div>Quick Check
Test your understanding of Tailwind CSS Mastery concepts from this lesson.
Lesson Recap
In this lesson you learned: flex-1 makes children claim equal shares of available space, flex-none prevents an item from growing or shrinking so it stays at its natural size, and grow, shrink, and basis-* provide granular control over each dimension separately. Next up we handle overflow with flex-wrap and create consistent gaps between flex items.
AI 튜터와 함께 HTML을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 30
- 레슨
- 120
자주 묻는 질문
“Flex 확장, 축소 및 기준 크기” 강의는 무료인가요?
네 — “Flex 확장, 축소 및 기준 크기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Tailwind CSS Academy 강의 전체를 잠금 해제할 수 있습니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
“Flex 확장, 축소 및 기준 크기”에서 뭘 배우나요?
flex-1, flex-none, grow, shrink, basis-* 유틸리티를 사용해 플렉스 자식 요소가 확장되거나 축소되는 방식을 조절합니다. 브라우저에서 직접 실행하는 실습 코드로 Tailwind CSS Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Tailwind CSS Academy을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Tailwind CSS Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“Flex 확장, 축소 및 기준 크기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Tailwind CSS Academy 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Tailwind CSS Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Flex와 방향 활성화
- 콘텐츠 배치와 항목 정렬
- Flex 확장, 축소 및 기준 크기
- 줄 바꿈과 간격