Languages/CSS

[CSS] Tailwind css๋ž€? / ์‚ฌ์šฉ๋ฒ•

MOONCO 2023. 3. 20. 12:21

๐Ÿ‘‰ Tailwind css๋ž€?

HTML ์•ˆ์—์„œ, CSS ์Šคํƒ€์ผ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” CSS ํ”„๋ ˆ์ž„์›Œํฌ

 

ํ•„์š”์„ฑ

์–ด๋–ค ๋ถ€๋ถ„์—, ์–ด๋–ค ์Šคํƒ€์ผ์„ ์ ์šฉํ•˜๋Š”์ง€ ํ•œ๋ˆˆ์— ๋ณผ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค!

 

PostCSS ํ”Œ๋Ÿฌ๊ทธ์ธ์œผ๋กœ ์„ค์น˜

npm install -D tailwindcss postcss autoprefixer

# postcss์™€ tailwindcss, autoprefixer ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜

 

PostCSS๋ž€?

 

[CSS/Node.js] PostCSS๋ž€? ์‚ฌ์šฉ๋ฒ•, ํ”Œ๋Ÿฌ๊ทธ์ธ ์ถ”์ฒœ

PostCSS๋ž€? CSS ํ›„์ฒ˜๋ฆฌ๊ธฐ์ด๋ฉฐ, CSS ์ž‘์„ฑ์„ ๋” ํŽธํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ๋Š” javascript ๋„๊ตฌ๋“ค(Plugins)์ด๋‹ค. javascript๋ฅผ ์ด์šฉํ•ด์„œ, CSS๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. ํ›„์ฒ˜๋ฆฌ๊ธฐ๋ž€? [CSS] CSS ์ „,ํ›„ ์ฒ˜๋ฆฌ๊ธฐ๋ž€? / ๋น„๊ต CSS ์ „,ํ›„ ์ฒ˜๋ฆฌ๊ธฐ๋ž€? C..

defineall.tistory.com

 

PostCSS ์„ค์ •

//postcss.config.js

module.exports = {
  plugins: {
    'postcss-import': {},
    tailwindcss: {},
    autoprefixer: {},
  }
}

 

Tailwind css ์ดˆ๊ธฐ ์„ค์ •

npx tailwindcss init

 

์„ค์ • ํŒŒ์ผ ์ˆ˜์ •

// tailwind.config.js

module.exports = {
  content: [
    "./src/**/*.{js,ts,jsx,tsx}", // ์ ์šฉํ•  jsํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ •
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

 

CSS์— Tailwind ๋„ฃ๊ธฐ

/* styles.css */

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

 

Tailwind ์ปค์Šคํ„ฐ ๋งˆ์ด์ง•ํ•˜๊ธฐ

// tailwind.config.js

// ์ปฌ๋Ÿฌ๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•˜๊ธฐ ์œ„ํ•œ tailwindcss/colors ๋ชจ๋“ˆ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

const colors = require('tailwindcss/colors')

module.exports = {
  darkMode: false, // or 'media' or 'class'
  theme: {
    // extend์™€ ๊ฒน์น˜๋Š” ์„ค์ •์ด ์žˆ์„ ๊ฒฝ์šฐ ๊ธฐ๋ณธ css ์Šคํƒ€์ผ์„ ์šฐ์„ ์‹œํ•œ๋‹ค.
    
    extend: {
      
      // ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ์ปฌ๋Ÿฌ๋ฅผ ๊ธฐ๋ณธ ์ปฌ๋Ÿฌ๋กœ ์ง€์ •ํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
      color: {
        gray: colors.coolGray,
        blue: colors.lightBlue,
        red: colors.rose,
        pink: colors.fuchsia,
      },
      
      // ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ํฐํŠธ๋ฅผ ๊ธฐ๋ณธ ํฐํŠธ๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
      fontFamily: {
        sans: ["Grapik", "sans-serif"],
        serif: ["Merriweather", "serif"],
      }
    }
  },
  ...
}

 

Tailwind ์‚ฌ์šฉ๋ฒ•

<button class="py-2 px-4 font-semibold rounded-lg shadow-md text-white bg-green-500 hover:bg-green-700">
    Hello, Tailwind CSS!
</button>

 

Tailwind ์ ์šฉ๋œ ๋ฒ„ํŠผ

 

์ˆ˜์น˜ ์ž…๋ ฅ
ml margin-left;
mx margin-left margin-right;
my margin-top margin-bottom;
pl padding-left;
px padding-left padding-right;
py padding-top padding-bottom;
w witdh;
max-w max-width;
h height;
max-h max-height;
ml-2 ํ˜•์‹์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค / margin-left : 2px;
auto auto;
full 100%;
screen 100vh or 100vw;

 

Display
block display: block;
inline-block display:inline-block;
inline display: inline;
flex display: flex
inline-flex display: inline-flex;
table display: table;
table-row display: table-row;
table-cell display: table-cell;
hidden display: none;

 

Position
static position: static;
fixed position: fixed;
absolute position: absolute;
relative position: relative;
sticky position: sticky;

 

Top / Right / Bottom / Left
inset-0 top: 0;
right: 0;
bottom: 0;
left: 0;
inset-x-0 right: 0;
left: 0;
inset-y-0 top: 0;
bottom: 0;
top-0 top: 0;
right-0 right: 0;
bottom-0 bottom: 0;
left-0 left: 0;

 

Text Transform
uppercase text-transform: uppercase;
lowercase test-transform: lowercase;
capitalize test-transform: capitalize;
normal-case test-transform: none;

 

z-index
z-0 z-index: 0;
z-10 z-index: 10;
z-auto z-index: auto;

 

Font-size
text-xs font-size: .75rem;
text-sm font-size: .875rem;
text-base font-size: 1rem;
text-lg font-size: 1.125rem;
text-2xl font-size: 1.5rem;
text-3cl font-size: 1.875rem;

 

Line-height
leading-none line-height: 1;
leading-tight line-height: 1.25;
leading-snug line-height: 1.375;
leading-normal line-height: 1.5;
leading-relaxed line-height: 1.625;
leading-loose line-height: 2;

 

Font-weight
font-hairline font-weight: 100;
font-thin font-weight: 200;
font-light font-weight: 300;
font-normal font-weight: 400;
font-medium font-weight: 500;
font-semibold font-weight: 600;
 font-bold font-weight: 700;
font-extrabold font-weight: 800;
font-black font-weight: 900;

 

Background-color
bg-transparent background-color: transparent;
bg-black background-color: #000;
bg-white background-color: #fff;
be-gray-100 background-color: #f7fafc;

 

Border style
border-solid border-style: solid;
border-dashed border-style: dashed;
border-dotted border-style: dotted;
border-double border-style: double;
border-none border-style: none;

 

Border color
border-transparent border-color: transparent;
border-black border-color: #000;
border-white border-color: #fff;
border-gray-100 border-color: #f7fafc;

 

Border size
border border-width: 1px;
border-0 border-width: 0;
border-2 border-width: 2px;
border-4 border-width: 4px;
border-t border-top-width: 1px; 
border-r border-right-width: 1px;
border-b border-bottom-width: 1px;
border-l border-left-width: 1px;

 

Border radius
rounded-none border-radius: 0;
rounded-sm border-radius: .125rem;
rounded border-radius: .25rem;
rounded-lg border-radius: .5rem;
rounded-full border-radius: .9999px;
rounded-tl-none border-top-left-radius: 0;
rounded-tr-none border-top-right-radius: 0;
rounded-bl-none border-bottom-left-radius: 0;
rounded-br-none border-bottom-right-radius: 0;
rounded-tl-full border-top-left-radius: 9999px;
rounded-tr-full border-top-right-radius: 9999px;
rounded-bl-full border-bottom-left-radius: 9999px;
rounded-br-full border-bottom-right-radius: 9999px;

 

Width / Height ( w๋ฅผ h๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด height )
w-0 width: 0; 
w-1 width: 0.25rem; 
... ...
w-auto width: auto; 
w-px width: 1px; 
w-1/2 width: 50%;
w-1/3 width: 33.333333%;
... ...
w-10/12 width: 83.333333%;
w-11/12 width: 91.666667%;
w-full width: 100%;
w-screen width: 100vw;

 

Padding / Margin ( p๋ฅผ m์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด Margin )
์ „์ฒด ์กฐ์ž‘
p-0 padding: 0; 
p-1 padding: 0.25rem; 
๊ฐ์ž ์กฐ์ž‘
px-0 padding-left: 0;
padding-right: 0;
px-1 padding-left: 0.25rem;
padding-right: 0.25rem;
py-0 padding-top: 0;
padding-bottom: 0;
py-1 padding-top: 0.25rem;
padding-bottom: 0.25rem;
pt-0 padding-top: 0;
pt-1 padding-top: 0.25rem;
pb-0 padding-bottom: 0;
pb-1 padding-bottom: 0.25rem;
pl-0 padding-left: 0;
pl-1 padding-left: 0.25rem;
pr-0 padding-right: 0;
pr-1 padding-right: 0.25rem;
ํ”ฝ์…€ ์กฐ์ž‘
p-px padding: 1px; 
px-px padding-right: 1px;
padding-left: 1px;
py-px padding-top: 1px;
padding-bottom: 1px;
pt-px padding-top: 1px;
pb-px padding-bottom: 1px;
pl-px padding-left: 1px;
pr-px padding-right: 1px;

 

Cursor
cursor-auto cursor: auto;
cursor-default cursor: default;
cursor-pointer cursor: pointer;
cursor-wait cursor: wait;
cursor-text cursor: text;
cursor-move cursor: move;
cursor-not-allowed cursor: not-allowed;

 

Opacity
opacity-100 opacity: 1;
opacity-75 opacity: .75;
opacity-50 opacity: .5;
opacity-25 opacity: .25;
opacity-0 opacity: 0;

 

 

๋ฐ˜์‘ํ˜•