/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
@tailwind base;
@tailwind components;
@tailwind utilities;
Tailwind CSS는 미리 정의된 유틸리티 클래스를 제공함.
CSS를 직접 작성하지 않고도 필요한 스타일을 쉽게 적용
ex) text-gray-500, bg-blue-500, rounded-lg
각각 텍스트 색상, 배경색, 모서리 둥글기
반응형 클래스를 제공
ex) sm:text-gray-500, md:bg-blue-500, lg:rounded-lg
각각 가로640px이상 색상 그레이 500, 가로768px이상 색상 블루 500,
1024px 이상 모서리 둥글게
hover, focus, active 등의 상태에 따른 스타일 적용을 지원
ex) hover:text-gray-700, focus:bg-blue-600, active:rounded-xl
각각 호버시 글씨색 회색 700, 포커스받았을때 배경 블루 600,
활성화 되었을때 모서리 라운드 0.75rem.
<!-- HTML -->
<div class="bg-gray-200 p-8 rounded-lg shadow-md">
<!-- 배경색: gray-200, 내부 여백: 32px, 모서리 둥글기: 12px, 그림자 효과 -->
<h2 class="text-2xl font-bold mb-4">Welcome to my website</h2>
<!-- 텍스트 크기: 2xl, 폰트 굵기: bold, 하단 여백: 16px -->
<p class="text-gray-600 leading-relaxed">
<!-- 텍스트 색상: gray-600, 줄 간격: relaxed -->
This is a simple example of using Tailwind CSS to style a website.
</p>
<button class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded mt-4">
<!-- 배경색: blue-500, 호버 시 배경색: blue-600, 텍스트 색상: white, 폰트 굵기: bold, 내부 여백: y축 8px, x축 16px, 모서리 둥글기: 기본, 상단 여백: 16px -->
Click me
</button>
</div>
// src/App.js
import React from 'react';
import Button from './components/Button';
function App() {
const handleClick = () => {
console.log('Button clicked!');
};
return (
<div className="bg-gray-200 p-8 rounded-lg shadow-md">
{/* 배경색: gray-200, 내부 여백: 32px, 모서리 둥글기: 12px, 그림자 효과 */}
<h2 className="text-2xl font-bold mb-4">
{/* 텍스트 크기: 2xl, 폰트 굵기: bold, 하단 여백: 16px */}
Welcome to my website
</h2>
<p className="text-gray-600 leading-relaxed mb-4">
{/* 텍스트 색상: gray-600, 줄 간격: relaxed, 하단 여백: 16px */}
This is an example of using Tailwind CSS in a React project.
</p>
<Button onClick={handleClick} className="mt-4">
{/* 사용자 정의 버튼 컴포넌트, 상단 여백: 16px */}
Click me
</Button>
</div>
);
}
export default App;