base, utility, component, layer
tailwind์์ ์ ๊ณตํ๋ ์คํ์ผ์ base, utility, component 3๊ฐ์ง์ ์ ํ์ผ๋ก ๋๋๋ค.
@base
base ํด๋์ค๋ ๊ธฐ๋ณธ html ์์์ ๋ํ css ์์ฑ์ ์ ์ํ๋ค. ์๋ฅผ ๋ค์ด ๋ชจ๋ span ์์์ ๊ธ์ ํฌ๊ธฐ๋ฅผ ์ ํ๊ณ ์ถ์ ๊ฒฝ์ฐ,
span {
@apply text-3xl font-bold;
}
์ฒ๋ผ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
@utilities
utility ํค์๋๋ ํน์ ์คํ์ผ ์์ฑ์ ํด๋์ค๋ก ์ ์ํ ๊ฒ์ ์๋ฏธํ๋ค.
<div className='flex flex-col items-center'>hi</div>
div {
display: flex;
flex-direction: column;
align-items: center;
}
ํ๋๋ tailwind๋ฅผ ์ฌ์ฉํด inline์ผ๋ก css๋ฅผ ์ ์ฉํ ๊ฒ์ด๊ณ , ์๋๋ ๊ฐ์ ์คํ์ผ์ ๊ธฐ๋ณธ css๋ฅผ ์ฌ์ฉํด์ ์ ์ฉํ ๊ฒ์ด๋ค.
flex-direction: column
์ flex-col
ํด๋์ค๋ก ์ฌ์ฉํ๋ ๊ฒ๋ค์ด ๋ฐ๋ก utility ํด๋์ค ๋ค์ด๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก tailwind ๋ฅผ ์ฌ์ฉํ์ฌ css๋ฅผ ์ ์ฉํ๊ฒ ๋ ๊ฒฝ์ฐ, ๋๋ถ๋ถ์ ํด๋์ค๊ฐ ๋ฐ๋ก utility ํด๋์ค์ ํด๋นํ๋ค.
@components
component ํด๋์ค๋ ์ฌ์ฌ์ฉ๊ฐ๋ฅํ ์ปดํฌ๋ํธ ui๋ฅผ ์ ์ํ๋ ํด๋์ค์ด๋ค. tailwind๋ inline์ผ๋ก css ๋ฅผ ์์ฑํด์ผ ํ๊ธฐ ๋๋ฌธ์ ๋ง์ css ๊ฐ ๋ค์ด๊ฐ๊ฒ ๋๋ฉด ํ์ฐ์ ์ผ๋ก html์ด ๊ธธ์ด์ง์ ๋ฐ์ ์๋ค. ๋ฐ๋ผ์ ๋ฐ๋ณต์ ์ผ๋ก ์ฌ์ฉ๋๋ component์ ๋ํด ํด๋์ค๋ฅผ ์ ์ฉํด ๊ฐ๋ ์ฑ๊ณผ ์ฌ์ฌ์ฉ์ฑ์ ๋์ผ์ ์๋ค.
@layer components{
.custom-button {
@apply p-3 rounded-lg bg-red-300 hover:bg-red-500 cursor-pointer text-center;
}
}
@layer
์ 2๊ฐ์ ํด๋์ค๋ฅผ ์ฌ์ฉํด๋ ๊ธฐ๋ณธ์ ์ผ๋ก inline ์ผ๋ก css๋ฅผ ์ ์ฉํ๊ธฐ ๋๋ฌธ์ html์ด ๊ธธ์ด์ ธ ๊ฐ๋ ์ฑ์ด ๋จ์ด์ง์๋ฐ์ ์๋ค.
์ด๋ด๋ ์ฌ์ฉ๊ฐ๋ฅํ๊ฒ์ด ๋ฐ๋ก layer ํค์๋์ธ๋ฐ, ์ด ํค์๋๋ฅผ ํตํด ํน์ ํด๋์ค์ ์ปค์คํ css ๋ฅผ ์ง์ ํ๋๊ฒ์ด ๊ฐ๋ฅํ๋ค.
@layer utilities {
.sort-vertical-flex {
@apply flex flex-col items-center
}
.sort-row-flex {
display: flex;
flex-direction: row;
align-items: center;
}
}
@layer components {
.custom-button {
@apply p-3 rounded-lg bg-red-300 hover:bg-red-500 cursor-pointer text-center;
}
}
@layer base {
html {
font-family: 'sans-serif;
font-size: 20px;
font-weight: 100;
color: #2e2e2e;
}
}
@layer utilities
๋ฅผ ๋ณด๋ฉด flex ๋ฅผ ์ด์ฉํด ์ ๋ ฌํ๋ css๋ฅผ ํ๋์ ํด๋์ค๋ก ๋ฌถ์ด ์ฌ์ฉํ ์ ์๋๋ก ํ๋ค.
์ฌ๊ธฐ์ ์ฌ์ฉ๋ @apply
ํค์๋๋ tailwind ํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ ์ปค์คํ
css๋ฅผ ์ ์ํ ์ ์๋๋ก ํด์ฃผ๋ฉฐ, ํด๋น ํค์๋๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ๊ธฐ๋ณธ css๋ง ์ฌ์ฉํด์ ์ ์ํ ์๋ ์๋ค.
์ถ๊ฐ์ ์ผ๋ก layer
ํค์๋๋ tailwind์ base, utility, component
ํด๋์ค์๋ง ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
Last updated