0Pricing
Tailwind CSS Academy · 강의

Grid 열 정의

grid-cols-1부터 grid-cols-12까지 사용해 다중 열 레이아웃을 만들고, 사용자 지정 구성을 위해 grid-cols-none을 사용합니다.

Grid 열 정의은(는) CoddyKit의 무료 Tailwind CSS Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Tailwind CSS Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

CSS Grid in Tailwind

CSS Grid is a two-dimensional layout system that lets you place items in rows and columns simultaneously. Tailwind CSS provides utility classes that map directly to CSS Grid properties, so you never have to write display: grid or grid-template-columns by hand. You simply add the right class names to your HTML elements.

<div class="grid">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

Activating Grid Display

To turn an element into a grid container, apply the grid class. Without any column definition, all children stack into a single column by default. This is the starting point for any Tailwind Grid layout — every grid utility you add builds on top of the grid class.

<!-- Single-column grid by default -->
<div class="grid gap-4">
  <div class="bg-blue-100 p-4">Card 1</div>
  <div class="bg-blue-100 p-4">Card 2</div>
  <div class="bg-blue-100 p-4">Card 3</div>
</div>

The grid-cols-N Utilities

Tailwind provides grid-cols-1 through grid-cols-12 to divide the container into equal-width columns. Under the hood, grid-cols-3 compiles to grid-template-columns: repeat(3, minmax(0, 1fr)). This means all columns share the available width equally, making it perfect for card grids and feature sections.

<!-- 3-column equal grid -->
<div class="grid grid-cols-3 gap-4">
  <div class="bg-green-100 p-4">Col 1</div>
  <div class="bg-green-100 p-4">Col 2</div>
  <div class="bg-green-100 p-4">Col 3</div>
  <div class="bg-green-100 p-4">Col 4</div>
  <div class="bg-green-100 p-4">Col 5</div>
  <div class="bg-green-100 p-4">Col 6</div>
</div>

Common Column Counts

Different column counts suit different use cases. A 2-column grid works well for split-content sections, 3 columns for feature rows, and 4 or 6 columns for product or image galleries. Tailwind supports every integer from 1 to 12, giving you the same range as Bootstrap's grid system but without the row wrappers.

<!-- 2-col layout -->
<div class="grid grid-cols-2 gap-6">
  <div class="bg-purple-100 p-6">Left panel</div>
  <div class="bg-purple-100 p-6">Right panel</div>
</div>

<!-- 4-col product grid -->
<div class="grid grid-cols-4 gap-4">
  <div class="bg-yellow-100 p-4">Product</div>
  <div class="bg-yellow-100 p-4">Product</div>
  <div class="bg-yellow-100 p-4">Product</div>
  <div class="bg-yellow-100 p-4">Product</div>
</div>

The 12-Column Grid System

The 12-column grid is a classic design convention because 12 is divisible by 1, 2, 3, 4, and 6, giving you lots of layout flexibility. With Tailwind's grid-cols-12, each child occupies one column by default. You then use col-span-* on individual children to make them span multiple columns — which we will explore in the next lesson.

<!-- 12-column base -->
<div class="grid grid-cols-12 gap-2">
  <!-- Each child spans 1 col unless told otherwise -->
  <div class="bg-red-100 p-2">1</div>
  <div class="bg-red-100 p-2">2</div>
  <div class="bg-red-100 p-2">3</div>
  <!-- ...up to 12 -->
</div>

grid-cols-none for Custom Grids

When the predefined 1–12 presets are not enough, use grid-cols-none to remove any column template, then define your own with grid-cols-[...] arbitrary values. The bracket notation lets you write any valid CSS grid-template-columns value directly inside a class name, giving you infinite flexibility without leaving HTML.

<!-- Custom column widths with arbitrary values -->
<div class="grid grid-cols-[200px_1fr_2fr] gap-4">
  <div class="bg-indigo-100 p-4">Fixed 200px</div>
  <div class="bg-indigo-100 p-4">1 fraction</div>
  <div class="bg-indigo-100 p-4">2 fractions</div>
</div>

Subgrid With Tailwind

Modern browsers support the subgrid keyword, which lets a nested grid inherit its parent's column tracks. Tailwind v3.4+ includes grid-cols-subgrid for this purpose. Subgrid is powerful for aligning form labels inside card components that sit in a parent grid — each card's internal elements align with the overall grid lines.

<!-- Parent grid with 3 columns -->
<div class="grid grid-cols-3 gap-4">
  <!-- Child that spans 2 cols and uses subgrid internally -->
  <div class="col-span-2 grid grid-cols-subgrid gap-2">
    <div class="bg-teal-100 p-3">A</div>
    <div class="bg-teal-100 p-3">B</div>
  </div>
  <div class="bg-teal-200 p-3">C</div>
</div>

Combining Grid With Gap

The gap-* utilities add consistent spacing between grid cells. Use gap-4 for uniform spacing in both directions, gap-x-4 for horizontal-only gaps, and gap-y-6 for vertical-only gaps. Unlike margins, gap does not add extra space on the outside edges of the grid, keeping your layout clean and predictable.

<!-- Different horizontal and vertical gaps -->
<div class="grid grid-cols-3 gap-x-8 gap-y-4">
  <div class="bg-orange-100 p-4">A</div>
  <div class="bg-orange-100 p-4">B</div>
  <div class="bg-orange-100 p-4">C</div>
  <div class="bg-orange-100 p-4">D</div>
  <div class="bg-orange-100 p-4">E</div>
  <div class="bg-orange-100 p-4">F</div>
</div>

Responsive Column Definitions

In most real-world layouts you want fewer columns on small screens and more on larger ones. Tailwind's responsive prefixes make this trivial: grid-cols-1 md:grid-cols-2 lg:grid-cols-4 stacks items on mobile, shows two columns on tablets, and four on desktops. This mobile-first approach means the unprefixed class is the baseline, and prefixed classes override it at larger breakpoints.

<!-- Mobile: 1 col, tablet: 2 cols, desktop: 4 cols -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
  <div class="bg-sky-100 p-6 rounded-lg">Card A</div>
  <div class="bg-sky-100 p-6 rounded-lg">Card B</div>
  <div class="bg-sky-100 p-6 rounded-lg">Card C</div>
  <div class="bg-sky-100 p-6 rounded-lg">Card D</div>
</div>

Auto-Fill vs Auto-Fit Columns

CSS Grid's auto-fill and auto-fit keywords create dynamic column counts based on available space. With Tailwind's arbitrary value syntax you can write grid-cols-[repeat(auto-fill,minmax(200px,1fr))] to automatically add columns as space allows. auto-fill keeps empty tracks, while auto-fit collapses them — both create truly fluid grids without media queries.

<!-- Auto-filling card grid: min 250px per card -->
<div class="grid gap-4" style="grid-template-columns: repeat(auto-fill, minmax(250px, 1fr))">
  <div class="bg-pink-100 p-4 rounded">Card 1</div>
  <div class="bg-pink-100 p-4 rounded">Card 2</div>
  <div class="bg-pink-100 p-4 rounded">Card 3</div>
  <div class="bg-pink-100 p-4 rounded">Card 4</div>
  <div class="bg-pink-100 p-4 rounded">Card 5</div>
</div>

Practical Three-Column Feature Grid

Putting it all together, here is a real feature section pattern used on marketing pages. Each feature card has an icon, heading, and description. The grid is grid-cols-1 sm:grid-cols-3 so it stacks on mobile and spreads into three columns on larger screens. Consistent padding and a subtle background create visual separation without borders.

<section class="grid grid-cols-1 sm:grid-cols-3 gap-8 px-8 py-12">
  <div class="text-center">
    <div class="text-4xl mb-4">🚀</div>
    <h3 class="font-bold text-lg mb-2">Fast</h3>
    <p class="text-gray-600">Ships in milliseconds.</p>
  </div>
  <div class="text-center">
    <div class="text-4xl mb-4">🔒</div>
    <h3 class="font-bold text-lg mb-2">Secure</h3>
    <p class="text-gray-600">Built-in protection.</p>
  </div>
  <div class="text-center">
    <div class="text-4xl mb-4">📱</div>
    <h3 class="font-bold text-lg mb-2">Responsive</h3>
    <p class="text-gray-600">Works on all devices.</p>
  </div>
</section>

Quick Check

Test your understanding of Tailwind CSS Mastery concepts from this lesson.

Lesson Recap

In this lesson you learned: the grid class activates a CSS Grid container, grid-cols-1 through grid-cols-12 define equal-width column tracks, and responsive prefixes like md:grid-cols-3 switch column counts at breakpoints. Next up we explore how to make grid items span multiple columns and rows for complex layouts.

자주 묻는 질문

“Grid 열 정의” 강의는 무료인가요?

네 — “Grid 열 정의” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Tailwind CSS Academy 강의 전체를 잠금 해제할 수 있습니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“Grid 열 정의”에서 뭘 배우나요?

grid-cols-1부터 grid-cols-12까지 사용해 다중 열 레이아웃을 만들고, 사용자 지정 구성을 위해 grid-cols-none을 사용합니다. 브라우저에서 직접 실행하는 실습 코드로 Tailwind CSS Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Tailwind CSS Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Tailwind CSS Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“Grid 열 정의” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Tailwind CSS Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Tailwind CSS Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Grid 열 정의
  2. 열과 행 걸치기
  3. Grid 행과 자동 배치
  4. Grid의 간격, 배치 및 정렬
← Tailwind CSS Academy(으)로 돌아가기