tailwindcss๋ ๋ถํธ์คํธ๋ฉ๊ณผ ๊ฐ์๋ฅ์ css framework์
๋๋ค.
tailwindcss๋ mobile-first์
๋๋ค. ๊ธฐ๋ณธ ๊ธฐ์คํ๋ฉด์ด mobile์
๋๋ค.
htmlํ๊ทธ๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ํ์ํ ๋์ pl-10์ด ๊ธฐ๋ณธ์ด๋ฉฐ lg:pl-20์ ํ๋ฉด์ ์คํฌ๋ฆฐ์ฌ์ด์ฆ๊ฐ 1024px์ด์์ผ๋ ์ ์ฉ๋ฉ๋๋ค.
<div class="pl-10 lg:pl-20">
module.exports = {
theme: {
screens: {
'sm': '640px',
// => @media (min-width: 640px) { ... }
'md': '768px',
// => @media (min-width: 768px) { ... }
'lg': '1024px',
// => @media (min-width: 1024px) { ... }
'xl': '1280px',
// => @media (min-width: 1280px) { ... }
'2xl': '1536px',
// => @media (min-width: 1536px) { ... }
}
}
}
install & config
[Terminal >> ๋ชจ๋ ์ธ์คํจ ๋ฐ ํ๊ฒฝ์ค์ ํ์ผ ์ด๊ธฐํ]
npm install -D tailwindcss
npx tailwindcss init
[์์ฑ๋ tailwind.config.js์ content๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์ค์ ํฉ๋๋ค.]
[tailwindcss build์ cshtml ์ฝ๋์ ํฌํจ๋ class๊ฐ ์คํ์ผ์ํธ๋ก output๋๊ฒ ์ค์ ํฉ๋๋ค.]
module.exports = {
content: [""./Pages/**/*.{cshtml,js}""],
theme: {
extend: {},
},
plugins: [],
}
[Pages/Src/Site.css ํ์ผ์ ์์ฑํ์ฌ ๋ค์ ๋ด์ฉ์ ๊ธฐ์
ํฉ๋๋ค.]
@tailwind base;
@tailwind components;
@tailwind utilities;
[Terminal >> tailwind.config.js๋ฅผ ์ค์ ์ผ๋ก stylesheet๊ฐ ์์ฑ๋ฉ๋๋ค.]
[tailwind.config.js์ ์ค์ ๋ content์ ํ์ผ์ ๊ฒ์ํ์ฌ ์ฌ์ฉ๋ class๋ค๋ง export๋ฉ๋๋ค.]
npx tailwindcss -i ./Pages/Src/site.css -o ./wwwroot/css/site.css --watch
3๊ฐ์ ์ข์์
๊ธฐ๋ณธ ํฐํธ ๋ณ๊ฒฝ์ tailwind.config.js์์ ๊ฐ๋ฅํฉ๋๋ค.
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
content: ["./Pages/**/*.{cshtml,js}"],
theme: {
fontFamily: {
'sans': ['OpenSans', 'Malgun Gothic', 'Dotum', 'sans-serif', defaultTheme.fontFamily.sans],
},
extend: {
},
},
plugins: [],
}
์ ๊ฐ์ ๊ฒฝ์ฐ Desktop-First๊ฐ ์ต์ํด์ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํ์ฌ ์ฌ์ฉํฉ๋๋ค.
์๋์ ๊ฐ์ด ์ค์ ํ๋ฉด screen์ด 576px ๋ณด๋ค ์์ผ๋ฉด sm ์ ํธ๋ฆฌํฐ๋ฅผ ์ด์ฉํ ํด๋์ค๋ค์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
module.exports = {
content: ["./Pages/**/*.{cshtml,js}"],
theme: {
screens: {
'sm': {'max':'576px'},
// => @media (max-width: 576px) { ... }
},
extend: {
},
},
plugins: [],
}
2๊ฐ์ ์ข์์
tailwindcss-question-mark of tailwindcss plugin
ํ๋ฐํธ ์์
์ค ๊ธด์ํ๊ฒ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ํด๋น github์ ์ค์น๋ฐฉ๋ฒ์ด ์ ๋์ ์์ต๋๋ค.
npm install tailwindcss-question-mark
// tailwind.config.js
module.exports = {
theme: {
// ...
},
plugins: [
require('tailwindcss-question-mark'),
// ...
],
}
3๊ฐ์ ์ข์์
asp.net core razor pages, blazor ๋ฑ์ tailwindcss๋ฅผ ๊ฐ๋ฐํ๊ฒฝ์์ ์ฌ์ฉํ ๋ ค๋ฉด ๋ถํธํ ์ ์ด ๋ง์ต๋๋ค.
ํด์, ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋ฐฐํฌ๋ ํ๊ฒฝ์์๋ ๊ถ์ฅํ์ง ์์ต๋๋ค.
์ ๋ฐฉ๋ฒ์ ์ด์ฉํ๋ฉด ํด๋น ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ inline style์ ์์ฑํด ์ฃผ๋ฏ๋ก tailwindcss๋ฅผ ๋งค๋ฒ ๋น๋ํ ํ์๊ฐ ์์ต๋๋ค.
ํ๋ฐ, ์ฌ์ฉํด๋ณด๋ฉด ์๋ฐ์คํฌ๋ฆฝํธ๊ฐ ๋ฌด๊ฑฐ์์ ๊ทธ๋ฐ์ง ์ฌ์ดํธ๊ฐ ๋ฒ๋ฒ
๊ฑฐ๋ฆฝ๋๋ค.
์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๋ฉด ํจ์ฌ ๊ฐ๋ฒผ์ด ๊ฐ์ ๋ ํ๊ฒฝ์์ ๊ฐ๋ฐ์ ํ
์คํธ ํ ์ ์์ต๋๋ค.
<head>
<script src="https://cdn.twind.style" crossorigin></script>
<script type="text/javascript">
const options =
{
"preflight": true,
"theme": {
"container": {
"center": true,
"padding": "0px",
"screens": {
"sm": "600px",
"md": "728px",
"lg": "960px",
"xl": "1280px",
"2xl": "1536px"
}
}
}
}
twind.install({
...options,
hash: (className) => className,
preflight: {
// Import external stylesheet
'@@import': `url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400&display=swap')`,
},
rules: [
[
// tailwindcss apply
'test-el',
'@@(bg-red-500)',
],
[
'test-el1',
'@@(font-bold text-white)'
]
]
})
</script>
</head>
<QuickGrid Items="@people">
<PropertyColumn Property="@(p => p.PersonId)" Sortable="true" Class="test-el test-el1" />
<PropertyColumn Property="@(p => p.Name)" Sortable="true" />
<PropertyColumn Property="@(p => p.PromotionDate)" Format="yyyy-MM-dd" Sortable="true" />
</QuickGrid>
2๊ฐ์ ์ข์์