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'),
// ...
],
}
![]()
4๊ฐ์ ์ข์์
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๊ฐ์ ์ข์์
์์ฆ hydro๋ก ์์
์ค์ธ๋ฐ asp.net core์์ tailwindcss๋ฅผ ์ฌ์ฉํ ๋ ์ ์ฉํ ๋ฐฉ๋ฒ์ธ๊ฒ ๊ฐ์ ์ถ๊ฐ์ ์ผ๋ก ๋ด์ฉ์ ๋จ๊น๋๋ค.
https://toolkit.usehydro.dev/installation/manual/
๊ธฐ์กด์๋ ํฐ๋ฏธ๋์์ npm์ผ๋ก ์ค์น๋ tailwindcss๋ฅผ watch์ต์
์ ์ค์ ์คํํด์ ์ฒ๋ฆฌํ์๋๋ฐ Tailwind Cli๋ฅผ HostedService๋ก ์ด์ฉํ ๋ฐฉ๋ฒ์ด ์๋ค์.
using System.Diagnostics;
namespace YourProject;
public class TailwindHostedService : IHostedService
{
private Process _process;
public Task StartAsync(CancellationToken cancellationToken)
{
_process = Process.Start(new ProcessStartInfo
{
FileName = "tailwindcss",
Arguments = "-i ./wwwroot/css/input.css -o ./wwwroot/css/output.css --watch",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
})!;
_process.EnableRaisingEvents = true;
_process.OutputDataReceived += (_, e) => LogInfo(e);
_process.ErrorDataReceived += (_, e) => LogInfo(e);
_process.BeginOutputReadLine();
_process.BeginErrorReadLine();
return Task.CompletedTask;
}
private static void LogInfo(DataReceivedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
Console.WriteLine($"Tailwind: {e.Data}");
}
}
public Task StopAsync(CancellationToken cancellationToken)
{
Console.WriteLine("Tailwind: STOP");
_process?.Kill(entireProcessTree: true);
return Task.CompletedTask;
}
}
4๊ฐ์ ์ข์์