Skip to content

Commit 958463c

Browse files
committed
update post
1 parent 0b0504e commit 958463c

File tree

3 files changed

+133
-3
lines changed

3 files changed

+133
-3
lines changed

content/posts/프로젝트/당근마켓 클론코딩/당근마켓 클론코딩으로 기본적인 tailwind 복습하기.md

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tags:
66
- clone
77
- tailwind
88
createdAt: 2025-06-14 15:04:37
9-
modifiedAt: 2025-06-29 15:25:25
9+
modifiedAt: 2025-06-29 15:46:52
1010
publish: 프로젝트/당근마켓 클론코딩
1111
related: ""
1212
series: ""
@@ -109,12 +109,142 @@ Tailwind에는 기본적으로 유용한 에니메이션들이 준비 되어 있
109109

110110
- `@import`: CSS파일을 인라인으로 가져올 때 사용
111111
- `@theme`: 글꼴, 색상, 중단점 등 웹사이트나 앱 디자인의 핵심 요소들을 '변수'처럼 만들어 재사용할 수 있도록 정의할때 사용
112+
113+
```css
114+
@theme {
115+
/* 1. 새로운 브랜드 색상 추가 */
116+
colors: {
117+
'primary': '#007BFF', /* 파란색 계열의 메인 색상 */
118+
'secondary': '#6C757D' /* 회색 계열의 보조 색상 */
119+
},
120+
121+
/* 2. 새로운 중단점(breakpoint) 추가 */
122+
screens: {
123+
'3xl': '1920px' /* 매우 큰 화면을 위한 중단점 */
124+
},
125+
126+
/* 3. 새로운 간격(spacing) 값 추가 */
127+
spacing: {
128+
'112': '28rem' /* 448px */
129+
}
130+
}
131+
```
132+
133+
```html
134+
<button class="bg-primary text-white p-4">Primary Button</button>
135+
136+
<div class="text-center 3xl:text-left">
137+
이 텍스트는 1920px 이상 화면에서 왼쪽 정렬됩니다.
138+
</div>
139+
140+
<div class="mt-112">위쪽에 28rem 만큼의 여백이 있습니다.</div>
141+
```
142+
112143
- `@source`: Tailwind의 자동 콘텐츠 감지에 포착되지 않는 소스 파일을 명시적으로 지정
113144
- `@utility`: hover, focus, lg와 같은 변형과 함께 작동하는 사용자 정의 유틸리티를 프로젝트에 추가
145+
146+
```css
147+
@utility .btn-blue {
148+
background-color: #3490dc;
149+
color: #ffffff;
150+
padding: 0.5rem 1rem;
151+
border-radius: 0.25rem;
152+
}
153+
154+
/* hover 시 배경색 변경 */
155+
@utility .btn-blue:hover {
156+
background-color: #2779bd;
157+
}
158+
```
159+
160+
```html
161+
<button class="btn-blue">Click me</button>
162+
```
163+
114164
- `@variant`: CSS의 스타일에 Tailwind 변형을 적용
165+
166+
```css
167+
/* 기본 카드 스타일 */
168+
.card-header {
169+
background-color: #f1f5f9; /* 기본 배경색 */
170+
transition: background-color 0.2s;
171+
}
172+
173+
/* 'group-hover' 변형을 '.card-header'에 적용
174+
=> 'group-hover:card-header' 클래스가 생성됨
175+
*/
176+
@variant group-hover & {
177+
.card-header {
178+
background-color: #e2e8f0; /* group-hover 시 변경될 배경색 */
179+
}
180+
}
181+
```
182+
183+
```html
184+
<div class="group border rounded-lg p-4">
185+
<div class="card-header group-hover:card-header p-2 rounded">
186+
Card Title
187+
</div>
188+
189+
<p class="mt-2">
190+
이 카드 전체(group)에 마우스를 올리면 제목의 배경색이 바뀝니다.
191+
</p>
192+
</div>
193+
```
194+
115195
- `@custom-variant`: 프로젝트에 사용자 정의 변형을 추가
196+
197+
```css
198+
/* 1. 'active'라는 이름의 새로운 변형을 정의합니다. */
199+
@custom-variant & active {
200+
/* `data-state='active'` 속성을 가진 요소에 스타일을 적용합니다. */
201+
&[data-state="active"] {
202+
@slot; /* 여기에 active:bg-blue-500 같은 유틸리티 스타일이 적용됩니다. */
203+
}
204+
}
205+
206+
/* (기타 Tailwind 코드) */
207+
@tailwind base;
208+
@tailwind components;
209+
@tailwind utilities;
210+
```
211+
212+
```html
213+
<div>
214+
<button
215+
class="px-4 py-2 rounded border
216+
active:bg-blue-500 active:text-white"
217+
data-state="inactive"
218+
>
219+
Tab 1
220+
</button>
221+
222+
<button
223+
class="px-4 py-2 rounded border
224+
active:bg-blue-500 active:text-white"
225+
data-state="active"
226+
>
227+
Tab 2
228+
</button>
229+
</div>
230+
```
231+
116232
- `@apply`: 기존 유틸리티 클래스를 사용자 정의 CSS에 인라인으로 적용
117233

234+
```css
235+
.btn {
236+
@apply bg-blue-500 text-white font-bold py-2 px-4 rounded;
237+
}
238+
239+
.btn:hover {
240+
@apply bg-blue-700;
241+
}
242+
```
243+
244+
```html
245+
<button class="btn">Click me</button>
246+
```
247+
118248
## Tailwind 플러그인 설치(v4)
119249

120250
`Tailwind`의 v4 버전부터는 기본적으로 `tailwind.config.js`를 사용하지 않는다. (원한다면 사용할 수 있음)

public/meta-data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@
546546
"tags": ["project", "carrot-market", "study", "clone", "tailwind"],
547547
"series": "",
548548
"createdAt": "2025-06-14 15:04:37",
549-
"modifiedAt": "2025-06-29 15:25:25",
549+
"modifiedAt": "2025-06-29 15:46:52",
550550
"publish": "프로젝트/당근마켓 클론코딩"
551551
},
552552
{

0 commit comments

Comments
 (0)