ReactNextCentral

호버, 포커스 및 기타 상태 다루기

Published on
호버, 포커스 등에서 요소를 스타일링하기 위해 유틸리티 사용하기
Table of Contents

Tailwind의 모든 유틸리티 클래스는 원하는 조건을 명시하는 수정자를 클래스 이름 앞에 추가하여 조건부로 적용될 수 있습니다.

예를 들어, bg-sky-700 클래스를 호버 시 적용하려면 hover:bg-sky-700 클래스를 사용하세요.

<button class="bg-sky-500 hover:bg-sky-700 ...">
  Save changes
</button>
이것이 전통적인 CSS와 어떻게 비교되나요?

전통적인 방식으로 CSS를 작성할 때, 하나의 클래스 이름이 현재 상태에 따라 다른 작업을 수행합니다.

기존 CSS 방식
전통적으로 같은 클래스 이름이 호버 시 다른 스타일을 적용합니다
.btn-primary {
  background-color: #0ea5e9;
}
.btn-primary:hover {
  background-color: #0369a1;
}

Tailwind에서는 기존 클래스에 호버 상태의 스타일을 추가하는 대신, 호버 시에만 작업을 수행하는 다른 클래스를 요소에 추가합니다.

Tailwind CSS 방식
Tailwind에서는 기본 상태와 호버 상태에 대해 별도의 클래스를 사용합니다
.bg-sky-500 {
  background-color: #0ea5e9;
}
.hover\:bg-sky-700:hover {
  background-color: #0369a1;
}

hover:bg-sky-700오직 :hover 상태에 대한 스타일만 정의하는 것에 주목하세요? 기본적으로는 아무것도 하지 않지만, 그 클래스가 적용된 요소에 호버하면 배경색이 sky-700으로 변경됩니다.

유틸리티 클래스를 조건부로 적용할 수 있다고 말할 때 이런 의미입니다. 수정자를 사용함으로써 HTML을 떠나지 않고도 다양한 상태에서 디자인이 어떻게 행동할지 정확히 제어할 수 있습니다.

Tailwind는 필요한 거의 모든 것을 위한 수정자를 포함하고 있으며, 여기에는 다음이 포함됩니다.

이러한 수정자는 특정 상황을 대상으로 더 구체적으로 변경하기 위해 겹쳐서 사용될 수 있습니다. 예를 들어, 다크 모드에서 중간 브레이크포인트에 호버할 때 배경색을 변경하는 경우:

<button class="dark:md:hover:bg-fuchsia-600 ...">
  Save changes
</button>

이 가이드에서는 프레임워크에서 사용할 수 있는 모든 수정자, 자신의 맞춤 클래스와 함께 사용하는 방법, 심지어 자신만의 수정자를 만드는 방법에 대해 알아볼 것입니다.

가상 클래스

호버, 포커스, 활성화

hover, focus, active 수정자를 사용하여 호버, 포커스, 활성화 시 요소를 스타일링하세요.

<button class="bg-violet-500 hover:bg-violet-600 active:bg-violet-700 focus:outline-none focus:ring focus:ring-violet-300 ...">
  Save changes
</button>

Tailwind는 :visited, :focus-within, :focus-visible 등과 같은 다른 대화형 상태를 위한 수정자도 포함하고 있습니다.

사용 가능한 가상 클래스 수정자의 전체 목록은 가상 클래스 참조를 참조하세요.

첫 번째, 마지막, 홀수, 짝수

firstlast 수정자를 사용하여 첫 번째 자식이나 마지막 자식일 때 요소를 스타일링하세요.

<ul role="list" class="p-6 divide-y divide-slate-200">
  {#each people as person}
    <li class="flex py-4 first:pt-0 last:pb-0">
      <img class="w-10 h-10 rounded-full" src="{person.imageUrl}" alt="" />
      <div class="ml-3 overflow-hidden">
        <p class="text-sm font-medium text-slate-900">{person.name}</p>
        <p class="text-sm truncate text-slate-500">{person.email}</p>
      </div>
    </li>
  {/each}
</ul>

홀수 자식이나 짝수 자식일 때 요소를 스타일링하려면 oddeven 수정자를 사용할 수도 있습니다.

Name

Title

Email

Jane Cooper

Regional Paradigm Technician

jane.cooper@example.com

Cody Fisher

Product Directives Officer

cody.fisher@example.com

Leonard Krasner

Senior Designer

leonard.krasner@example.com

Emily Selman

VP, Hardware Engineering

emily.selman@example.com

Anna Roberts

Chief Strategy Officer

anna.roberts@example.com

<table>
  <!-- ... -->
  <tbody>
    {#each people as person}
      <tr class="odd:bg-white even:bg-slate-50">
        <td>{person.name}</td>
        <td>{person.title}</td>
        <td>{person.email}</td>
      </tr>
    {/each}
  </tbody>
</table>

Tailwind는 :only-child, :first-of-type, :empty 등과 같은 다른 구조적 가상 클래스를 위한 수정자도 포함하고 있습니다.

사용 가능한 가상 클래스 수정자의 전체 목록을 보려면 가상 클래스 참조를 참조하세요.

폼 상태

required, invalid, disabled와 같은 수정자를 사용하여 다양한 상태의 폼 요소를 스타일링하세요.

<form>
  <label class="block">
    <span class="block text-sm font-medium text-slate-700">Username</span>
    <!-- 폼 상태 수정자를 사용하면, 모든 입력에 대해 클래스를 동일하게 사용할 수 있습니다 -->
    <input type="text" value="tbone" disabled class="block w-full px-3 py-2 mt-1 text-sm bg-white border rounded-md shadow-sm border-slate-300 placeholder-slate-400 focus:outline-none focus:border-sky-500 focus:ring-1 focus:ring-sky-500 disabled:bg-slate-50 disabled:text-slate-500 disabled:border-slate-200 disabled:shadow-none invalid:border-pink-500 invalid:text-pink-600 focus:invalid:border-pink-500 focus:invalid:ring-pink-500 "/>
  </label>
  <!-- ... -->
</form>

이런 식으로 수정자를 사용하면 템플릿에서 조건부 로직의 양을 줄일 수 있어 입력의 상태에 관계없이 동일한 클래스 세트를 사용할 수 있으며 브라우저가 적절한 스타일을 적용할 수 있습니다.

Tailwind는 :read-only, :indeterminate, :checked 등과 같은 다른 폼 상태를 위한 수정자도 포함하고 있습니다.

사용 가능한 가상 클래스 수정자의 전체 목록을 보려면 가상 클래스 참조를 참조하세요.

부모 상태에 따른 스타일링 (group-{modifier})

어떤 부모 요소의 상태에 따라 요소를 스타일링할 필요가 있을 때, 부모에 group 클래스를 표시하고 group-* 수정자들을 사용하여 대상 요소를 스타일링하세요. 예를 들어 group-hover와 같은 수정자를 사용할 수 있습니다.

New project

Create a new project from a variety of starting templates.

<a href="#" class="block max-w-xs p-6 mx-auto space-y-3 bg-white rounded-lg shadow-lg group ring-1 ring-slate-900/5 hover:bg-sky-500 hover:ring-sky-500">
  <div class="flex items-center space-x-3">
    <svg class="w-6 h-6 stroke-sky-500 group-hover:stroke-white" fill="none" viewBox="0 0 24 24"><!-- ... --></svg>
    <h3 class="text-sm font-semibold text-slate-900 group-hover:text-white">새 프로젝트</h3>
  </div>
  <p class="text-sm text-slate-500 group-hover:text-white">다양한 시작 템플릿에서 새 프로젝트를 생성하세요.</p>
</a>

이 패턴은 group-focus, group-active, 심지어 group-odd와 같은 모든 가상 클래스 수정자와 함께 작동합니다.

중첩된 그룹 구분하기

그룹을 중첩할 때, group/{name} 클래스를 사용하여 특정 부모 그룹에 고유한 그룹 이름을 지정하고 group-hover/{name}과 같은 클래스를 사용하여 해당 이름을 수정자에 포함시켜 특정 부모 그룹의 상태에 따라 스타일을 지정할 수 있습니다.

<ul role="list">
  {#each people as person}
    <li class="group/item hover:bg-slate-100 ...">
      <img src="{person.imageUrl}" alt="" />
      <div>
        <a href="{person.url}">{person.name}</a>
        <p>{person.title}</p>
      </div>
      <a class="group/edit invisible hover:bg-slate-200 group-hover/item:visible ..." href="tel:{person.phone}">
        <span class="group-hover/edit:text-gray-700 ...">Call</span>
        <svg class="group-hover/edit:translate-x-0.5 group-hover/edit:text-slate-500 ...">
          <!-- ... -->
        </svg>
      </a>
    </li>
  {/each}
</ul>

그룹은 원하는 대로 이름을 지정할 수 있으며 어떤 방식으로도 설정할 필요가 없습니다. 마크업에서 직접 그룹을 이름 지정하면 Tailwind가 필요한 CSS를 자동으로 생성합니다.

임의 그룹

대괄호 사이에 임의 값으로 자신만의 선택자를 제공함으로써 즉석에서 group-* 수정자를 생성할 수 있습니다.

<div class="group is-published">
  <div class="hidden group-[.is-published]:block">
    발행됨
  </div>
</div>
.group.is-published .group-\[\.is-published\]\:block {
  display: block;
}

더 많은 제어를 위해 최종 선택자에서 .group이 어떻게 나타날지를 표시하기 위해 & 문자를 사용할 수 있습니다.

<div class="group">
  <div class="group-[:nth-of-type(3)_&]:block">
    <!-- ... -->
  </div>
</div>
:nth-of-type(3) .group .group-\[\:nth-of-type\(3\)_\&\]\:block {
  display: block;
}

형제 요소 상태에 따른 스타일링 (peer-{modifier})

형제 요소의 상태에 따라 요소를 스타일링할 필요가 있을 때, 형제에 peer 클래스를 표시하고 peer-* 수정자를 사용하여 대상 요소를 스타일링하세요. 예를 들어 peer-invalid를 사용할 수 있습니다.

<form>
  <label class="block">
    <span class="block text-sm font-medium text-slate-700">Email</span>
    <input type="email" class="peer ..."/>
    <p class="invisible mt-2 text-sm text-pink-600 peer-invalid:visible">
      Please provide a valid email address.
    </p>
  </label>
</form>

이를 통해 JS 없이도 플로팅 라벨과 같은 다양한 멋진 트릭을 구현할 수 있습니다.

이 패턴은 peer-focus, peer-required, peer-disabled 등 모든 가상 클래스 수정자와 함께 작동합니다.

CSS에서 이후 형제 결합자의 작동 방식 때문에 peer 마커는 이전 형제에만 사용될 수 있다는 점을 알아두는 것이 중요합니다.

기존 CSS 방식
이전 형제만 피어로 표시될 수 있으므로 작동하지 않습니다
<label>
  <span class="peer-invalid:text-red-500 ...">Email</span>
  <input type="email" class="peer ..."/>
</label>

피어 구분하기

여러 피어를 사용할 때, peer/{name} 클래스를 사용하여 특정 피어에 고유한 이름을 지정하고 peer-checked/{name}과 같은 클래스에서 그 이름을 수정자로 포함시켜 특정 피어의 상태에 따라 스타일을 지정할 수 있습니다.

Published status
<fieldset>
  <legend>Published status</legend>

  <input id="draft" class="peer/draft" type="radio" name="status" checked />
  <label for="draft" class="peer-checked/draft:text-sky-500">Draft</label>

  <input id="published" class="peer/published" type="radio" name="status" />
  <label for="published" class="peer-checked/published:text-sky-500">Published</label>

  <div class="hidden peer-checked/draft:block">Drafts are only visible to administrators.</div>
  <div class="hidden peer-checked/published:block">Your post will be publicly visible on your site.</div>
</fieldset>

피어는 원하는 대로 이름을 지정할 수 있으며 어떤 방식으로도 설정할 필요가 없습니다. 마크업에서 직접 피어를 이름 지정하면 Tailwind가 필요한 CSS를 자동으로 생성합니다.

임의의 피어

대괄호 사이에 임의 값으로 자신만의 선택자를 제공함으로써 즉석에서 peer-* 수정자를 생성할 수 있습니다.

<form>
  <label for="email">이메일:</label>
  <input id="email" name="email" type="email" class="is-dirty peer" required />
  <div class="peer-[.is-dirty]:peer-required:block hidden">이 필드는 필수입니다.</div>
  <!-- ... -->
</form>
.peer.is-dirty:required ~ .peer-\[\.is-dirty\]\:peer-required\:block {
  display: block;
}

최종 선택자에서 .peer가 어떻게 나타날지를 표시하기 위해 & 문자를 사용할 수 있으며, 이를 통해 전달한 선택자에 대해 더 많은 제어가 가능합니다.

<div>
  <input type="text" class="peer" />
  <div class="hidden peer-[:nth-of-type(3)_&]:block">
    <!-- ... -->
  </div>
</div>
:nth-of-type(3) .peer ~ .peer-\[\:nth-of-type\(3\)_\&\]\:block {
  display: block;
}

직계 자식 스타일링 (*-{modifier})

일반적으로 자식 요소에 유틸리티 클래스를 직접 적용하는 것이 선호되지만, 제어할 수 없는 직계 자식을 스타일링해야 하는 상황에서는 * 수정자를 사용할 수 있습니다.

Categories

Sales
Marketing
SEO
Analytics
Design
Strategy
Security
Growth
Mobile
UX/UI
<div>
  <h2>Categories<h2>
  <ul class="*:rounded-full *:border *:border-sky-100 *:bg-sky-50 *:px-2 *:py-0.5 dark:text-sky-300 dark:*:border-sky-500/15 dark:*:bg-sky-500/10 ...">
    <li>Sales</li>
    <li>Marketing</li>
    <li>SEO</li>
    <!-- ... -->
  </ul>
</div>

직접 자식에 유틸리티를 적용하여 스타일을 오버라이딩하는 것은 생성된 자식 선택자의 구체성 때문에 작동하지 않는다는 점을 알아두는 것이 중요합니다.

기존 CSS 방식
작동하지 않습니다, 자식은 자신의 스타일링을 오버라이드할 수 없습니다.
<ul class="*:bg-sky-50 ...">
  <li class="bg-red-50 ...">Sales</li>
  <li>Marketing</li>
  <li>SEO</li>
  <!-- ... -->
</ul>

자손에 따른 스타일링 (has-{modifier})

has-* 수정자를 사용하여 자손의 상태나 내용에 기반한 요소의 스타일을 지정하세요.

Payment method
<label class="has-[:checked]:bg-indigo-50 has-[:checked]:text-indigo-900 has-[:checked]:ring-indigo-200 ..">
  <svg fill="currentColor">
    <!-- ... -->
  </svg>
  Google Pay
  <input type="radio" class="checked:border-indigo-500 ..." />
</label>

가상 클래스와 함께 has-*를 사용하여, 예를 들어 has-[:focus]를 통해 자손의 상태에 기반한 요소의 스타일을 지정할 수 있습니다. 또한 요소 선택자를 사용하여, has-[img]has-[a]와 같이 자손의 내용에 기반한 요소의 스타일을 지정할 수도 있습니다.

그룹의 자손에 따른 스타일링 (group-has-{modifier})

부모 요소의 자손에 기반하여 요소를 스타일링할 필요가 있을 때, 부모에 group 클래스를 표시하고 group-has-* 수정자를 사용하여 대상 요소를 스타일링할 수 있습니다.

Spencer Sharp

Product Designer at planeteria.tech

Casey Jordan

Just happy to be here.

Alex Reed

A multidisciplinary designer, working at the intersection of art and technology.
alex-reed.com

Taylor Bailey

Pushing pixels. Slinging divs.

<div class="group ...">
  <img src="..." />
  <h4>Spencer Sharp</h4>
  <svg class="hidden group-has-[a]:block ...">
    <!-- ... -->
  </svg>
  <p>Product Designer at <a href="...">planeteria.tech</a></p>
</div>

형제의 자손에 따른 스타일링 (peer-has-{modifier})

형제 요소의 자손에 기반하여 요소를 스타일링할 필요가 있을 때, 형제에 peer 클래스를 표시하고 peer-has-* 수정자를 사용하여 대상 요소를 스타일링할 수 있습니다.

Today
<fieldset>
  <legend>오늘</legend>

  <div>
    <label class="peer ...">
      <input type="checkbox" name="todo[1]" checked />
      할 일 목록 만들기
    </label>
    <svg class="peer-has-[:checked]:hidden ...">
      <!-- ... -->
    </svg>
  </div>

  <!-- ... -->
</fieldset>

가상 요소

before와 after

beforeafter 수정자를 사용하여 ::before::after 가상 요소를 스타일링하세요.

<label class="block">
  <span class="after:content-['*'] after:ml-0.5 after:text-red-500 block text-sm font-medium text-slate-700">
    이메일
  </span>
  <input type="email" name="email" class="block w-full px-3 py-2 mt-1 bg-white border rounded-md shadow-sm border-slate-300 placeholder-slate-400 focus:outline-none focus:border-sky-500 focus:ring-sky-500 sm:text-sm focus:ring-1" placeholder="you@example.com" />
</label>

이 수정자를 사용할 때, Tailwind는 기본적으로 content: ''를 자동으로 추가하므로 다른 값을 원하지 않는 한 지정할 필요가 없습니다.

When you look annoyed all the time, people think that you're busy.

<blockquote class="text-2xl italic font-semibold text-center text-slate-900">
  When you look
  <span class="relative inline-block before:block before:absolute before:-inset-1 before:-skew-y-3 before:bg-pink-500">
    <span class="relative text-white">annoyed</span>
  </span>
  all the time, people think that you're busy.
</blockquote>

대부분의 Tailwind 프로젝트에서 ::before::after 가상 요소가 필요하지 않다는 점을 알아두는 것이 좋습니다 — 실제 HTML 요소를 사용하는 것이 보통 더 간단합니다.

예를 들어, 위의 디자인을 ::before 가상 요소 대신 <span>을 사용하여 표현한 것은 읽기 더 쉽고 실제로 코드도 더 적습니다.

<blockquote class="text-2xl italic font-semibold text-center text-slate-900">
  When you look
  <span class="relative">
    <span class="absolute block -skew-y-3 bg-pink-500 -inset-1" aria-hidden="true"></span>
    <span class="relative text-white">annoyed</span>
  </span>
  all the time, people think that you're busy.
</blockquote>

beforeafter는 가상 요소의 내용이 실제 DOM에 없고 사용자가 선택할 수 없는 상황에서 중요할 때 사용하세요.

Preflight 기본 스타일을 비활성화한 경우, content 속성이 기본적으로 빈 문자열로 설정되지 않으므로 beforeafter 수정자를 사용할 때마다 content-['']를 포함해야 한다는 점을 참고하세요.

Preflight를 비활성화한 경우 content를 수동으로 설정하세요.

<div class="before:content-[''] before:block ...">
  <!-- ... -->
</div>

플레이스홀더 텍스트 스타일링

placeholder 수정자를 사용하여 입력란이나 텍스트 영역의 플레이스홀더 텍스트를 스타일링하세요.

<label class="relative block">
  <span class="sr-only">검색</span>
  <span class="absolute inset-y-0 left-0 flex items-center pl-2">
    <svg class="w-5 h-5 fill-slate-300" viewBox="0 0 20 20"><!-- ... --></svg>
  </span>
  <input class="block w-full py-2 pr-3 bg-white border rounded-md shadow-sm placeholder:italic placeholder:text-slate-400 border-slate-300 pl-9 focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm" placeholder="아무것이나 검색하세요..." type="text" name="search"/>
</label>

파일 입력 버튼 스타일링

file 수정자를 사용하여 파일 입력의 버튼을 스타일하세요.

Current profile photo
<form class="flex items-center space-x-6">
  <div class="shrink-0">
    <img class="object-cover w-16 h-16 rounded-full" src="https://images.unsplash.com/photo-1580489944761-15a19d654956?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1361&q=80" alt="Current profile photo" />
  </div>
  <label class="block">
    <span class="sr-only">프로필 사진 선택</span>
    <input type="file" class="block w-full text-sm text-slate-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-violet-50 file:text-violet-700 hover:file:bg-violet-100 "/>
  </label>
</form>

Tailwind의 테두리 초기화는 파일 입력 버튼에 적용되지 않습니다. 이는 파일 입력 버튼에 테두리를 추가하려면 file:border-solid과 같은 클래스를 사용하여 명시적으로 테두리 스타일을 설정해야 함을 의미합니다.

<input type="file" class="file:border file:border-solid ..." />

목록 마커 스타일링

marker 수정자를 사용하여 목록의 카운터나 불릿을 스타일하세요.

Ingredients

  • 5 cups chopped Porcini mushrooms
  • 1/2 cup of olive oil
  • 3lb of celery
<ul role="list" class="pl-5 space-y-3 list-disc marker:text-sky-400 text-slate-500" dark-class="pl-5 space-y-3 list-disc marker:text-sky-400 text-slate-400">
  <li>5컵의 다진 포르치니 버섯</li>
  <li>올리브 오일 1/2컵</li>
  <li>셀러리 3파운드</li>
</ul>

marker 수정자는 상속 가능하게 디자인되어 있어서 <li> 요소에 직접 사용할 수 있지만, 반복을 피하기 위해 부모에도 사용할 수 있습니다.

강조된 텍스트

selection 수정자를 사용하여 활성 텍스트 선택을 스타일하세요.

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<div class="selection:bg-fuchsia-300 selection:text-fuchsia-900">
  <p>
    So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I <em>was</em> a marine biologist.
  </p>
</div>

selection 수정자는 상속 가능하도록 설계되었으므로, 트리의 어디에나 추가할 수 있고 모든 자손 요소에 적용됩니다.

이를 통해 사이트 전체에서 브랜드와 일치하는 선택 색상을 쉽게 설정할 수 있습니다.

<html>
<head>
  <!-- ... -->
</head>
<body class="selection:bg-pink-300">
  <!-- ... -->
</body>
</html>

첫 줄과 첫 글자 스타일링

콘텐츠 블록의 첫 줄을 스타일링하려면 first-line 수정자를 사용하고, 첫 글자를 스타일링하려면 first-letter 수정자를 사용하세요.

Well, let me tell you something, funny boy. Y'know that little stamp, the one that says "New York Public Library"? Well that may not mean anything to you, but that means a lot to me. One whole hell of a lot.

Sure, go ahead, laugh if you want to. I've seen your type before: Flashy, making the scene, flaunting convention. Yeah, I know what you're thinking. What's this guy making such a big stink about old library books? Well, let me give you a hint, junior.

<p class="first-line:uppercase first-line:tracking-widest first-letter:text-7xl first-letter:font-bold first-letter:text-slate-900 first-letter:mr-3 first-letter:float-left"
 dark-class="first-line:uppercase first-line:tracking-widest first-letter:text-7xl first-letter:font-bold first-letter:text-white first-letter:mr-3 first-letter:float-left"
">
  Well, let me tell you something, funny boy. Y'know that little stamp, the one
  that says "New York Public Library"? Well that may not mean anything to you,
  but that means a lot to me. One whole hell of a lot.
</p>

대화 상자 배경 스타일링

backdrop 수정자를 사용하여 기본 <dialog> 요소의 배경을 스타일하세요.

<dialog class="backdrop:bg-gray-50">
  <form method="dialog">
    <!-- ... -->
  </form>
</dialog>

프로젝트에서 기본 <dialog> 요소를 사용하는 경우, open 수정자를 사용하여 열린/닫힌 상태의 스타일링에 대해 알아볼 수도 있습니다.

미디어 및 기능 쿼리

반응형 브레이크포인트

특정 브레이크포인트에서 요소를 스타일링하려면 md, lg와 같은 반응형 수정자를 사용하세요.

예를 들어, 이 코드는 모바일에서 3열 그리드, 중간 너비 화면에서 4열 그리드, 넓은 너비 화면에서 6열 그리드를 렌더링합니다.

<div class="grid grid-cols-3 md:grid-cols-4 lg:grid-cols-6">
  <!-- ... -->
</div>

이러한 기능이 어떻게 작동하는지 자세히 알아보려면 반응형 디자인 문서를 확인하세요.

선호 색상 체계

prefers-color-scheme 미디어 쿼리는 사용자가 밝은 테마 또는 어두운 테마를 선호하는지 알려주며, 보통 운영 체제 수준에서 설정됩니다.

밝은 모드를 대상으로 하려면 수정자 없이 유틸리티를 사용하고, 어두운 모드에 대한 오버라이드를 제공하려면 dark 수정자를 사용하세요.

Light mode

Writes Upside-Down

The Zero Gravity Pen can be used to write in any orientation, including upside-down. It even works in outer space.

Dark mode

Writes Upside-Down

The Zero Gravity Pen can be used to write in any orientation, including upside-down. It even works in outer space.

<div class="px-6 py-8 bg-white rounded-lg shadow-xl dark:bg-slate-900 ring-1 ring-slate-900/5">
  <div>
    <span class="inline-flex items-center justify-center p-2 bg-indigo-500 rounded-md shadow-lg">
      <svg class="w-6 h-6 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true"><!-- ... --></svg>
    </span>
  </div>
  <h3 class="mt-5 text-base font-medium tracking-tight text-slate-900 dark:text-white">뒤집혀서 쓸 수 있음</h3>
  <p class="mt-2 text-sm text-slate-500 dark:text-slate-400">
    제로 중력 펜은 어떤 방향으로도 쓸 수 있으며, 심지어 우주 공간에서도 작동합니다.
  </p>
</div>

이 기능이 어떻게 작동하는지 자세히 알아보려면 다크 모드 문서를 확인하세요.

움직임 감소 선호

prefers-reduced-motion 미디어 쿼리는 사용자가 필수적이지 않은 움직임을 최소화하도록 요청했는지 알려줍니다.

사용자가 움직임 감소를 요청했을 때 조건부로 스타일을 추가하려면 motion-reduce 수정자를 사용하세요.

<button type="button" class="bg-indigo-500 ..." disabled>
  <svg class="motion-reduce:hidden animate-spin ..." viewBox="0 0 24 24"><!-- ... --></svg>
  처리 중...
</button>

Tailwind는 또한 사용자가 움직임 감소를 요청하지 _않았을 때_만 스타일을 추가하는 motion-safe 수정자도 포함하고 있습니다. 이는 motion-reduce 도우미를 사용할 때 많은 스타일을 "되돌려야" 하는 경우 유용할 수 있습니다.

<!-- `motion-reduce`를 사용하면 스타일을 많이 되돌려야 할 수 있습니다 -->
<button class="hover:-translate-y-0.5 transition motion-reduce:hover:translate-y-0 motion-reduce:transition-none ...">
  변경 사항 저장
</button>

<!-- 이런 상황에서 `motion-safe`는 코드가 더 적습니다 -->
<button class="motion-safe:hover:-translate-x-0.5 motion-safe:transition ...">
  변경 사항 저장
</button>

대비 선호

prefers-contrast 미디어 쿼리는 사용자가 더 높거나 낮은 대비를 요청했는지 알려줍니다.

사용자가 더 높은 대비를 요청했을 때 조건부로 스타일을 추가하려면 contrast-more 수정자를 사용하세요.

We need this to steal your identity.

<form>
  <label class="block">
    <span class="block text-sm font-medium text-slate-700">사회 보장 번호</span>
    <input class="border-slate-200 placeholder-slate-400 contrast-more:border-slate-400 contrast-more:placeholder-slate-500"/>
    <p class="mt-2 text-sm opacity-10 contrast-more:opacity-100 text-slate-600">
      이 정보는 귀하의 신원을 도용하기 위해 필요합니다.
    </p>
  </label>
</form>

Tailwind는 또한 사용자가 낮은 대비를 요청했을 때 조건부로 스타일을 추가할 수 있는 contrast-less 수정자도 포함하고 있습니다.

강제 색상 모드

forced-colors 미디어 쿼리는 사용자가 강제 색상 모드를 사용하고 있는지를 나타냅니다. 이러한 모드는 사이트의 색상을 사용자가 정의한 팔레트로 텍스트, 배경, 링크 및 버튼의 색상을 덮어씁니다.

사용자가 강제 색상 모드를 활성화했을 때 조건부로 스타일을 추가하려면 forced-colors 수정자를 사용하세요.

Choose a theme:
<form>
  <legend> 테마 선택: </legend>
  <label>
    <input type="radio" class="appearance-none forced-colors:appearance-auto" />
    <p class="hidden forced-colors:block">
      시안
    </p>
    <div class="forced-colors:hidden h-6 w-6 rounded-full bg-cyan-200 ..."></div>
    <div class="forced-colors:hidden h-6 w-6 rounded-full bg-cyan-500 ..."></div>
  </label>
  <!-- ... -->
</form>

Tailwind는 강제 색상 조정을 위해 forced color adjust 유틸리티도 포함하고 있어 강제 색상의 적용을 선택적으로 사용하거나 배제할 수 있습니다.

뷰포트 방향

portraitlandscape 수정자를 사용하여 뷰포트의 특정 방향일 때 조건부로 스타일을 추가하세요.

<div>
  <div class="portrait:hidden">
    <!-- ... -->
  </div>
  <div class="landscape:hidden">
    <p>
      이 경험은 가로 방향으로 보기 위해 디자인되었습니다. 사이트를 보려면 기기를 회전하세요.
    </p>
  </div>
</div>

인쇄 스타일

print 수정자를 사용하여 문서를 인쇄할 때만 적용되는 스타일을 조건부로 추가하세요.

<div>
  <article class="print:hidden">
    <h1>나만의 비밀 피자 레시피</h1>
    <p>이 레시피는 비밀이며, 누구와도 공유해서는 안 됩니다</p>
    <!-- ... -->
  </article>
  <div class="hidden print:block">
    진짜로 이걸 인쇄하려고 하나요? 비밀인데요!
  </div>
</div>

지원 규칙 사용하기

사용자의 브라우저에서 특정 기능이 지원되는지 여부에 따라 스타일을 지정하려면 supports-[...] 수정자를 사용하세요.

<div class="flex supports-[display:grid]:grid ...">
  <!-- ... -->
</div>

내부적으로 supports-[...] 수정자는 @supports 규칙을 생성하고, 대괄호 사이에 @supports (...)와 함께 사용할 수 있는 속성/값 쌍이나 and, or를 사용하는 표현식을 포함할 수 있습니다.

간결성을 위해 특정 값을 확인할 필요 없이 속성이 지원되는지만 확인해야 할 경우, 속성 이름만 지정할 수 있습니다.

<div class="bg-black/75 supports-[backdrop-filter]:bg-black/25 supports-[backdrop-filter]:backdrop-blur ...">
  <!-- ... -->
</div>

프로젝트에서 자주 사용하는 @supports 규칙을 tailwind.config.js 파일의 theme.supports 섹션에서 단축키로 구성할 수 있습니다.

/** @type {import('tailwindcss').Config} */
module.exports = {
  theme: {
    supports: {
      grid: 'display: grid',
    },
  },
}

이제 이러한 사용자 정의 supports-* 수정자를 프로젝트에서 사용할 수 있습니다.

<div class="supports-grid:grid">
  <!-- ... -->
</div>

속성 선택자

ARIA 상태

ARIA 속성을 기반으로 조건부로 스타일을 적용하려면 aria-* 수정자를 사용하세요.

예를 들어, aria-checked 속성이 true로 설정된 경우 bg-sky-700 클래스를 적용하려면 aria-checked:bg-sky-700 클래스를 사용하세요.

<div aria-checked="true" class="bg-gray-600 aria-checked:bg-sky-700">
  <!-- ... -->
</div>

기본적으로 가장 일반적인 불리언 ARIA 속성에 대한 수정자가 포함되어 있습니다.

수정자CSS
aria-busy[aria-busy="true"]
aria-checked[aria-checked="true"]
aria-disabled[aria-disabled="true"]
aria-expanded[aria-expanded="true"]
aria-hidden[aria-hidden="true"]
aria-pressed[aria-pressed="true"]
aria-readonly[aria-readonly="true"]
aria-required[aria-required="true"]
aria-selected[aria-selected="true"]

tailwind.config.js 파일의 theme.aria 또는 theme.extend.aria를 편집하여 사용 가능한 aria-* 수정자를 사용자 정의할 수 있습니다.

module.exports = {
  theme: {
    extend: {
      aria: {
        asc: 'sort="ascending"',
        desc: 'sort="descending"',
      },
    },
  },
};

테마에 포함시키기에 적합하지 않은 일회성 aria 수정자가 필요하거나 특정 값을 취하는 더 복잡한 ARIA 속성을 사용해야 하는 경우, 임의 값으로 속성을 생성하기 위해 대괄호를 사용할 수 있습니다.

Invoice #

ClientAmount
#100Pendant Publishing$2,000.00
#101Kruger Industrial Smoothing$545.00
#102J. Peterman$10,000.25
<table>
  <thead>
    <tr>
      <th aria-sort="ascending" class="aria-[sort=ascending]:bg-[url('/img/down-arrow.svg')] aria-[sort=descending]:bg-[url('/img/up-arrow.svg')]">
        Invoice #
      </th>
      <!-- ... -->
    </tr>
  </thead>
  <!-- ... -->
</table>
.aria-[sort=ascending]:bg-[url('/img/down-arrow.svg')][aria-sort=ascending] {
  background-image: url('/img/down-arrow.svg');
}

.aria-[sort=descending]:bg-[url('/img/up-arrow.svg')][aria-sort=descending] {
  background-image: url('/img/up-arrow.svg');
}

ARIA 상태 수정자는 group-aria-*peer-aria-* 수정자를 사용하여 부모 및 형제 요소를 대상으로 할 수도 있습니다.

<table>
  <thead>
    <tr>
      <th aria-sort="ascending" class="group">
        Invoice #
        <svg class="group-aria-[sort=ascending]:rotate-0 group-aria-[sort=descending]:rotate-180"><!-- ... --></svg>
      </th>
      <!-- ... -->
    </tr>
  </thead>
  <!-- ... -->
</table>
.group[aria-sort=ascending] .group-aria-[sort=ascending]:rotate-0 {
  --tw-rotate: 0deg;
  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

.group[aria-sort=descending] .group-aria-[sort=descending]:rotate-180 {
  --tw-rotate: 180deg;
  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}

데이터 속성

데이터 속성을 기반으로 조건부로 스타일을 적용하려면 data-* 수정자를 사용하세요.

정의에 따라 표준 data-* 속성이 없기 때문에 기본적으로는 임의의 값만 지원합니다. 예를 들어:

<!-- 적용됩니다 -->
<div data-size="large" class="data-[size=large]:p-8">
  <!-- ... -->
</div>

<!-- 적용되지 않습니다 -->
<div data-size="medium" class="data-[size=large]:p-8">
  <!-- ... -->
</div>

프로젝트에서 자주 사용하는 일반 데이터 속성 선택자에 대한 단축키를 tailwind.config.js 파일의 theme.data 섹션에서 구성할 수 있습니다.

module.exports = {
  theme: {
    data: {
      checked: 'ui~="checked"',
    },
  },
}

그런 다음 이러한 사용자 정의 data-* 수정자를 프로젝트에서 사용할 수 있습니다.

<div data-ui="checked active" class="data-checked:underline">
  <!-- ... -->
</div>

RTL 지원

다방향 레이아웃을 구축할 때 오른쪽에서 왼쪽(rtl)과 왼쪽에서 오른쪽(ltr) 모드에 각각 조건부로 스타일을 추가하기 위해 rtlltr 수정자를 사용하세요.

Left-to-right

Tom Cook

Director of Operations

Right-to-left

تامر كرم

الرئيس التنفيذي

<div class="flex items-center group">
  <img class="w-12 h-12 rounded-full shrink-0" src="..." alt="" />
  <div class="ltr:ml-3 rtl:mr-3">
    <p class="text-sm font-medium text-slate-700 group-hover:text-slate-900" dark-class="text-sm font-medium text-slate-300 group-hover:text-white">...</p>
    <p class="text-sm font-medium text-slate-500 group-hover:text-slate-700" dark-class="text-sm font-medium text-slate-500 group-hover:text-slate-300">...</p>
  </div>
</div>

ltr 수정자는 dir 속성이 명시적으로 ltr로 설정된 경우에만 효과가 나타나므로, 다방향 사이트를 구축할 때는 rtl 모드뿐만 아니라 항상 방향을 설정해야 합니다.

왼쪽에서 오른쪽이 기본이라도 항상 방향을 설정하세요

<html dir="ltr">
  <!-- ... -->
</html>

이러한 수정자는 왼쪽에서 오른쪽 및 오른쪽에서 왼쪽 레이아웃을 모두 지원해야 하는 사이트를 구축할 때만 유용합니다. 단일 방향만 지원해야 하는 사이트를 구축하는 경우 이러한 수정자는 필요 없으며, 내용에 맞는 스타일을 적용하기만 하면 됩니다.

열림/닫힘 상태

<details> 또는 <dialog> 요소가 열린 상태일 때 조건부로 스타일을 추가하려면 open 수정자를 사용하세요.

Why do they call it Ovaltine?

The mug is round. The jar is round. They should call it Roundtine.

<div class="max-w-lg p-8 mx-auto">
  <details class="p-6 rounded-lg open:bg-white dark:open:bg-slate-900 open:ring-1 open:ring-black/5 dark:open:ring-white/10 open:shadow-lg" open>
    <summary class="text-sm font-semibold leading-6 select-none text-slate-900 dark:text-white">
      왜 오발틴이라고 부를까?
    </summary>
    <div class="mt-3 text-sm leading-6 text-slate-600 dark:text-slate-400">
      <p>머그는 둥글고, 병도 둥글다. 라운드틴이라고 불러야 맞다.</p>
    </div>
  </details>
</div>

사용자 정의 수정자

임의의 변형 사용

임의 값을 사용해 유틸리티 클래스에 사용자 정의 값을 사용할 수 있듯이, 임의의 변형을 사용하면 HTML에서 직접 사용자 정의 선택자 수정자를 작성할 수 있습니다.

임의의 변형은 선택자를 나타내는 형식 문자열로, 대괄호로 감싸집니다. 예를 들어, 다음 임의 수정자는 세 번째 자식 요소만을 선택합니다.

<ul role="list">
  {#each items as item}
    <li class="[&:nth-child(3)]:underline">{item}</li>
  {/each}
</ul>
.[&:nth-child(3)]:underline:nth-child(3) {
  text-decoration-style: underline
}

형식 문자열은 addVariant 플러그인 API에서 사용하는 것과 동일하며, &는 수정되는 선택자를 나타냅니다.

임의의 변형은 기본 수정자나 다른 임의의 수정자와 마찬가지로 쌓을 수 있습니다.

<ul role="list">
  {#each items as item}
    <li class="lg:[&:nth-child(3)]:hover:underline">{item}</li>
  {/each}
</ul>
@media (min-width: 1024px) {
  .lg:[&:nth-child(3)]:hover:underline:hover:nth-child(3) {
    text-decoration-line: underline;
  }
}

선택자에 공백이 필요한 경우 밑줄을 사용할 수 있습니다. 예를 들어, 다음 임의 수정자는 클래스가 추가된 요소 내의 모든 p 요소를 선택합니다.

<div class="[&_p]:mt-4">
  <p>Lorem ipsum...</p>
  <ul>
    <li>
      <p>Lorem ipsum...</p>
    </li>
    <!-- ... -->
  </ul>
</div>
.[&_p]:mt-4 p {
    margin-top: 1rem;
}

@media@supports와 같은 at-규칙도 임의의 변형에 사용할 수 있습니다.

<div class="flex [@supports(display:grid)]:grid">
  <!-- ... -->
</div>
@supports (display: grid) {
  .[@supports(display:grid)]:grid {
    display: grid;
  }
}

at-규칙 사용자 정의 수정자에서는 & 자리표시자가 필요 없습니다. at-규칙 후에 중괄호 내에 일반 선택자 수정자를 포함시켜 at-규칙과 일반 선택자 수정자를 결합할 수도 있습니다.

<button type="button" class="[@media(any-hover:hover){&:hover}]:opacity-100">
  <!-- ... -->
</button>
@media (any-hover: hover) {
  .[@media(any-hover:hover){&:hover}]:opacity-100:hover {
    opacity: 1
  }
}

플러그인 생성

프로젝트에서 동일한 임의 수정자를 여러 번 사용하는 경우 addVariant API를 사용하여 플러그인으로 추출하는 것이 좋을 수 있습니다.

let plugin = require('tailwindcss/plugin')

module.exports = {
  // ...
  plugins: [
    plugin(function ({ addVariant }) {
      // 'third' 변형을 추가, 예: `third:pb-0`
      addVariant('third', '&:nth-child(3)')
    })
  ]
}

변형 플러그인 추가 문서에서 자세한 정보를 확인하세요.

고급 주제

자체 클래스와 함께 사용하기

Tailwind의 레이어 중 하나에서 정의했거나 플러그인을 사용하여 추가한 경우, Tailwind의 모든 수정자를 자체 커스텀 클래스와 함께 사용할 수 있습니다.

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer utilities {
  .content-auto {
    content-visibility: auto;
  }
}
<div class="lg:content-auto">
  <!-- ... -->
</div>

중첩 수정자 순서

수정자를 중첩할 때는 중첩된 함수 호출처럼 안에서 바깥으로 적용됩니다.

// 다음 수정자들:
'dark:group-hover:focus:opacity-100'

// 다음과 같이 적용됩니다.
dark(groupHover(focus('opacity-100')))

대부분의 경우 이 순서는 실제로 중요하지 않지만, 사용하는 순서에 따라 의미 있는 차이를 만들어내는 몇 가지 상황이 있습니다.

예를 들어, darkModeclass로 설정한 경우 darkgroup-hover 수정자를 결합하면 사용하는 순서에 따라 다른 결과가 생성됩니다.

/* dark:group-hover:opacity-100 */
.dark .group:hover .dark\:group-hover\:opacity-100 {
  opacity: 1;
}

/* group-hover:dark:opacity-100 */
.group:hover .dark .group-hover\:dark\:opacity-100 {
  opacity: 1;
}

첫 번째 예제에서는 dark 요소가 group 요소의 부모여야 하지만 두 번째 예제에서는 그 반대입니다.

이것이 중요한 또 다른 경우는 공식 타이포그래피 플러그인과 함께 제공되는 prose-headings와 같은 수정자를 사용할 때입니다.

/* prose-headings:hover:underline */
.prose-headings\:hover\:underline:hover :is(:where(h1, h2, h3, h4, th)) {
  text-decoration: underline;
}

/* hover:prose-headings:underline */
.hover\:prose-headings\:underline :is(:where(h1, h2, h3, h4, th)):hover {
  text-decoration: underline;
}

첫 번째 예제에서는 기사 전체에 마우스를 올리면 모든 제목에 밑줄이 그어지지만, 두 번째 예제에서는 각 제목에 마우스를 올렸을 때만 해당 제목에 밑줄이 그어집니다.

빠른 참조

Tailwind에서 기본적으로 포함된 모든 수정자에 대한 빠른 참조 표입니다.

수정자CSS
hover&:hover
focus&:focus
focus-within&:focus-within
focus-visible&:focus-visible
active&:active
visited&:visited
target&:target
*& > *
has&:has
first&:first-child
last&:last-child
only&:only-child
odd&:nth-child(odd)
even&:nth-child(even)
first-of-type&:first-of-type
last-of-type&:last-of-type
only-of-type&:only-of-type
empty&:empty
disabled&:disabled
enabled&:enabled
checked&:checked
indeterminate&:indeterminate
default&:default
required&:required
valid&:valid
invalid&:invalid
in-range&:in-range
out-of-range&:out-of-range
placeholder-shown&:placeholder-shown
autofill&:autofill
read-only&:read-only
before&::before
after&::after
first-letter&::first-letter
first-line&::first-line
marker&::marker
selection&::selection
file&::file-selector-button
backdrop&::backdrop
placeholder&::placeholder
sm@media (min-width: 640px)
md@media (min-width: 768px)
lg@media (min-width: 1024px)
xl@media (min-width: 1280px)
2xl@media (min-width: 1536px)
min-[...]@media (min-width: ...)
max-sm@media not all and (min-width: 640px)
max-md@media not all and (min-width: 768px)
max-lg@media not all and (min-width: 1024px)
max-xl@media not all and (min-width: 1280px)
max-2xl@media not all and (min-width: 1536px)
max-[...]@media (max-width: ...)
dark@media (prefers-color-scheme: dark)
portrait@media (orientation: portrait)
landscape@media (orientation: landscape)
motion-safe@media (prefers-reduced-motion: no-preference)
motion-reduce@media (prefers-reduced-motion: reduce)
contrast-more@media (prefers-contrast: more)
contrast-less@media (prefers-contrast: less)
print@media print
supports-[...]@supports (...)
aria-checked&[aria-checked="true"]
aria-disabled&[aria-disabled="true"]
aria-expanded&[aria-expanded="true"]
aria-hidden&[aria-hidden="true"]
aria-pressed&[aria-pressed="true"]
aria-readonly&[aria-readonly="true"]
aria-required&[aria-required="true"]
aria-selected&[aria-selected="true"]
aria-[...]&[aria-...]
data-[...]&[data-...]
rtl[dir="rtl"] &
ltr[dir="ltr"] &
open&[open]

의사 클래스 참조

이것은 Tailwind에 포함된 모든 의사 클래스 수정자에 대한 예시 목록으로, 이 가이드 초반의 의사 클래스 문서를 보완합니다.

호버 (:hover)

사용자가 마우스 커서로 요소 위에 있을 때 스타일을 적용하려면 hover 수정자를 사용하세요.

<div class="bg-black hover:bg-white ...">
  <!-- ... -->
</div>

포커스 (:focus)

요소가 포커스를 받았을 때 스타일을 적용하려면 focus 수정자를 사용하세요.

<input class="border-gray-300 focus:border-blue-400 ..." />

포커스-위딘 (:focus-within)

요소나 그 자손 중 하나가 포커스를 받았을 때 스타일을 적용하려면 focus-within 수정자를 사용하세요.

<div class="focus-within:shadow-lg ...">
  <input type="text" />
</div>

포커스-비지블 (:focus-visible)

키보드를 사용하여 포커스된 요소에 스타일을 적용하려면 focus-visible 수정자를 사용하세요.

<button class="focus:outline-none focus-visible:ring ...">
  제출
</button>

의사 클래스 참조

활성 (:active)

요소가 눌려질 때 스타일을 적용하려면 active 수정자를 사용하세요.

<button class="bg-blue-500 active:bg-blue-600 ...">
  제출
</button>

방문함 (:visited)

링크가 이미 방문된 상태일 때 스타일을 적용하려면 visited 수정자를 사용하세요.

<a href="https://seinfeldquotes.com" class="text-blue-600 visited:text-purple-600 ...">
  영감
</a>

대상 (:target)

ID가 현재 URL 조각과 일치하는 요소에 스타일을 적용하려면 target 수정자를 사용하세요.

<div id="about" class="target:shadow-lg ...">
  <!-- ... -->
</div>

첫 번째 (:first-child)

요소가 첫 번째 자식일 때 스타일을 적용하려면 first 수정자를 사용하세요.

<ul>
  {#each people as person}
    <li class="py-4 first:pt-0 ...">
      <!-- ... -->
    </li>
  {/each}
</ul>

의사 클래스 참조

마지막 자식 (:last-child)

요소가 마지막 자식일 때 스타일을 적용하려면 last 수정자를 사용하세요.

<ul>
  {#each people as person}
    <li class="py-4 last:pb-0 ...">
      <!-- ... -->
    </li>
  {/each}
</ul>

유일한 자식 (:only-child)

요소가 유일한 자식일 때 스타일을 적용하려면 only 수정자를 사용하세요.

<ul>
  {#each people as person}
    <li class="py-4 only:py-0 ...">
      <!-- ... -->
    </li>
  {/each}
</ul>

홀수 자식 (:nth-child(odd))

요소가 홀수 번째 자식일 때 스타일을 적용하려면 odd 수정자를 사용하세요.

<table>
  {#each people as person}
    <tr class="bg-white odd:bg-gray-100 ...">
      <!-- ... -->
    </tr>
  {/each}
</table>

의사 클래스 참조

짝수 자식 (:nth-child(even))

요소가 짝수 번째 자식일 때 스타일을 적용하려면 even 수정자를 사용하세요.

<table>
  {#each people as person}
    <tr class="bg-white even:bg-gray-100 ...">
      <!-- ... -->
    </tr>
  {/each}
</table>

유형의 첫 번째 자식 (:first-of-type)

특정 유형의 첫 번째 자식일 때 스타일을 적용하려면 first-of-type 수정자를 사용하세요.

<nav>
  <img src="/logo.svg" alt="Vandelay Industries" />
  {#each links as link}
    <a href="#" class="ml-2 first-of-type:ml-6 ...">
      <!-- ... -->
    </a>
  {/each}
</nav>

유형의 마지막 자식 (:last-of-type)

특정 유형의 마지막 자식일 때 스타일을 적용하려면 last-of-type 수정자를 사용하세요.

<nav>
  <img src="/logo.svg" alt="Vandelay Industries" />
  {#each links as link}
    <a href="#" class="mr-2 last-of-type:mr-6 ...">
      <!-- ... -->
    </a>
  {/each}
  <button>More</button>
</nav>

유형의 유일한 자식 (:only-of-type)

특정 유형의 유일한 자식일 때 스타일을 적용하려면 only-of-type 수정자를 사용하세요.

<nav>
  <img src="/logo.svg" alt="Vandelay Industries" />
  {#each links as link}
    <a href="#" class="mx-2 only-of-type:mx-6 ...">
      <!-- ... -->
    </a>
  {/each}
  <button>More</button>
</nav>

내용이 없는 요소 (:empty)

요소가 비어 있을 때 스타일을 적용하려면 empty 수정자를 사용하세요.

<ul>
  {#each people as person}
    <li class="empty:hidden ...">{person.hobby}</li>
  {/each}
</ul>

비활성화된 입력 요소 (:disabled)

입력 요소가 비활성화되었을 때 스타일을 적용하려면 disabled 수정자를 사용하세요.

<input class="disabled:opacity-75 ..." />

활성화된 입력 요소 (:enabled)

입력 요소가 활성화되었을 때 스타일을 적용하려면 enabled 수정자를 사용하세요. 이는 요소가 비활성화되지 않았을 때 다른 스타일을 적용하고 싶을 때 유용합니다.

<input class="enabled:hover:border-gray-400 disabled:opacity-75 ..." />

선택된 상태 (:checked)

체크박스나 라디오 버튼이 선택된 상태일 때 스타일을 적용하려면 checked 수정자를 사용하세요.

<input type="checkbox" class="appearance-none checked:bg-blue-500 ..." />

불확정 상태 (:indeterminate)

체크박스나 라디오 버튼이 불확정 상태일 때 스타일을 적용하려면 indeterminate 수정자를 사용하세요.

<input type="checkbox" class="appearance-none indeterminate:bg-gray-300 ..." />

기본값 상태 (:default)

페이지가 처음 로드될 때 기본값이었던 옵션, 체크박스 또는 라디오 버튼에 스타일을 적용하려면 default 수정자를 사용하세요.

<input type="checkbox" class="default:ring-2 ..." />

필수 입력 필드 (:required)

필수 입력 필드에 스타일을 적용하려면 required 수정자를 사용하세요.

<input class="required:border-red-500 ..." />

유효한 입력 필드 (:valid)

입력 필드가 유효한 상태일 때 스타일을 적용하려면 valid 수정자를 사용하세요.

<input class="valid:border-green-500 ..." />

유효하지 않을 때 (:invalid)

입력 필드가 유효하지 않은 상태일 때 스타일을 적용하려면 invalid 수정자를 사용하세요.

<input class="invalid:border-red-500 ..." />

범위 내 (:in-range)

입력값이 지정된 범위 내에 있을 때 스타일을 적용하려면 in-range 수정자를 사용하세요.

<input min="1" max="5" class="in-range:border-green-500 ..." />

범위 초과 (:out-of-range)

입력값이 지정된 범위를 벗어났을 때 스타일을 적용하려면 out-of-range 수정자를 사용하세요.

<input min="1" max="5" class="out-of-range:border-red-500 ..." />

플레이스홀더 표시 (:placeholder-shown)

플레이스홀더가 표시될 때 스타일을 적용하려면 placeholder-shown 수정자를 사용하세요.

<input class="placeholder-shown:border-gray-500 ..." placeholder="you@example.com" />

자동 완성 (:autofill)

브라우저에 의해 자동 완성된 입력 필드에 스타일을 적용하려면 autofill 수정자를 사용하세요.

<input class="autofill:bg-yellow-200 ..." />

읽기 전용 (:read-only)

입력 필드가 읽기 전용일 때 스타일을 적용하려면 read-only 수정자를 사용하세요.

<input class="read-only:bg-gray-100 ..." />