この記事の要点
• flex・grid・p-4・m-4のユーティリティクラスで高速レイアウト
• レスポンシブはsm:/md:/lg:プレフィックスで制御
• hover:・focus:で状態に応じたスタイルを簡潔に適用
レイアウト
Display
| クラス | 説明 |
|---|
block | ブロック要素 |
inline-block | インラインブロック要素 |
inline | インライン要素 |
flex | フレックスコンテナ |
inline-flex | インラインフレックス |
grid | グリッドコンテナ |
hidden | 非表示 |
Flexbox
<div class="flex flex-row">横並び</div>
<div class="flex flex-col">縦並び</div>
<div class="flex flex-wrap">折り返し</div>
<div class="flex justify-start">左揃え</div>
<div class="flex justify-center">中央</div>
<div class="flex justify-end">右揃え</div>
<div class="flex justify-between">両端揃え</div>
<div class="flex justify-around">均等配置</div>
<div class="flex justify-evenly">均等配置(等間隔)</div>
<div class="flex items-start">上揃え</div>
<div class="flex items-center">中央揃え</div>
<div class="flex items-end">下揃え</div>
<div class="flex items-stretch">伸縮</div>
<div class="flex-1">残りを埋める</div>
<div class="flex-none">固定サイズ</div>
<div class="flex-shrink-0">縮小しない</div>
<div class="flex-grow">伸びる</div>
Grid
<div class="grid grid-cols-3">3カラム</div>
<div class="grid grid-cols-4">4カラム</div>
<div class="grid grid-cols-12">12カラム</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4">
レスポンシブグリッド
</div>
<div class="grid gap-4">16px間隔</div>
<div class="grid gap-x-4 gap-y-2">x:16px y:8px</div>
<div class="col-span-2">2列分</div>
<div class="col-span-full">全幅</div>
ポイント: flexとgridの使い分け: 1次元(横並び/縦並び)にはFlex、2次元(行と列)にはGridが適しています。
スペーシング
Padding / Margin
<div class="p-4">全方向 16px</div>
<div class="px-4">左右 16px</div>
<div class="py-4">上下 16px</div>
<div class="pt-4">上 16px</div>
<div class="pr-4">右 16px</div>
<div class="pb-4">下 16px</div>
<div class="pl-4">左 16px</div>
<div class="m-4">全方向 16px</div>
<div class="mx-auto">左右中央</div>
<div class="my-4">上下 16px</div>
<div class="mt-4">上 16px</div>
<div class="-mt-4">上 -16px</div>
Gap
<div class="flex gap-4">16px間隔</div>
<div class="flex gap-x-4">横 16px間隔</div>
<div class="flex gap-y-2">縦 8px間隔</div>
サイズ
Width / Height
<div class="w-full">100%</div>
<div class="w-1/2">50%</div>
<div class="w-1/3">33.33%</div>
<div class="w-64">256px</div>
<div class="w-screen">100vw</div>
<div class="max-w-md">max-width: 28rem</div>
<div class="max-w-xl">max-width: 36rem</div>
<div class="min-w-0">min-width: 0</div>
<div class="h-full">100%</div>
<div class="h-screen">100vh</div>
<div class="h-64">256px</div>
<div class="min-h-screen">min-height: 100vh</div>
実践メモ: スペーシングスケールは1 = 4pxが基本。p-4は16px、m-8は32px。この法則を覚えると数値がすぐ分かります。
タイポグラフィ
フォントサイズ
| クラス | サイズ |
|---|
text-xs | 12px |
text-sm | 14px |
text-base | 16px |
text-lg | 18px |
text-xl | 20px |
text-2xl | 24px |
text-3xl | 30px |
text-4xl | 36px |
フォントウェイト
| クラス | ウェイト |
|---|
font-thin | 100 |
font-light | 300 |
font-normal | 400 |
font-medium | 500 |
font-semibold | 600 |
font-bold | 700 |
テキスト配置
| クラス | 配置 |
|---|
text-left | 左揃え |
text-center | 中央 |
text-right | 右揃え |
text-justify | 両端揃え |
色
| クラス | 色 |
|---|
text-gray-500 | グレー |
text-red-500 | 赤 |
text-blue-500 | 青 |
text-green-500 | 緑 |
text-black | 黒 |
text-white | 白 |
背景・ボーダー
背景色
| クラス | 説明 |
|---|
bg-white | 白 |
bg-gray-100 | 薄いグレー |
bg-blue-500 | 青 |
bg-gradient-to-r from-blue-500 to-purple-500 | グラデーション |
ボーダー
| クラス | 説明 |
|---|
border | 1pxボーダー |
border-2 | 2pxボーダー |
border-gray-300 | グレーボーダー |
border-t | 上のみ |
border-b | 下のみ |
rounded | 4px角丸 |
rounded-md | 6px角丸 |
rounded-lg | 8px角丸 |
rounded-xl | 12px角丸 |
rounded-full | 完全な円 |
シャドウ
| クラス | 説明 |
|---|
shadow | 小さな影 |
shadow-md | 中程度 |
shadow-lg | 大きな影 |
shadow-xl | より大きな影 |
shadow-none | 影なし |
注意: Tailwindのブレークポイントはモバイルファーストです。md:w-1/2は「768px以上で半分の幅」という意味。指定なしがモバイルの基本スタイルになります。
レスポンシブ
<div class="w-full md:w-1/2 lg:w-1/3">
レスポンシブ幅
</div>
<div class="flex flex-col md:flex-row">
モバイル: 縦 / PC: 横
</div>
<div class="hidden md:block">
md以上で表示
</div>
<div class="md:hidden">
md未満で表示
</div>
ポイント: hidden md:blockは「モバイルでは非表示、md以上で表示」。逆にmd:hiddenは「md以上で非表示」。レスポンシブの出し分けに必須です。
ホバー・状態
| 状態 | クラス例 | 説明 |
|---|
| ホバー | bg-blue-500 hover:bg-blue-600 | ホバー時に背景色変更 |
| ホバー透明度 | opacity-50 hover:opacity-100 | ホバーで不透明に |
| フォーカス | focus:ring-2 focus:ring-blue-500 | フォーカス時にリング表示 |
| アクティブ | active:scale-95 | クリック時に縮小 |
| 無効 | disabled:opacity-50 | 無効時に透明度変更 |
アニメーション
| クラス | 説明 |
|---|
transition | 全トランジション |
transition-colors | 色のみ |
transition-transform | 変形のみ |
duration-300 | 0.3秒 |
ease-in-out | イージング |
hover:scale-105 transition-transform | ホバーで拡大 |
animate-spin | 回転 |
animate-pulse | 点滅 |
animate-bounce | バウンス |
実践メモ: transitionクラスとhover:を組み合わせるとスムーズなアニメーションに。duration-300で0.3秒のトランジションが定番です。
注意: @applyの多用は避けましょう。Tailwindの利点(HTML上で直接スタイルが分かる)が失われます。共通パターンはコンポーネント化で対応するのがベストプラクティスです。
よく使うパターン
カード
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-bold mb-2">タイトル</h2>
<p class="text-gray-600">説明文</p>
</div>
ボタン
<button class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded">
ボタン
</button>
インプット
<input class="border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" />
中央揃え
<div class="flex items-center justify-center min-h-screen">
中央
</div>
参考リソース
関連記事
この技術を体系的に学びたいですか?
未来学では東証プライム上場企業のITエンジニアが24時間サポート。月額24,800円から、退会金0円のオンラインIT塾です。
メールで無料相談する
← 一覧に戻る