[Tailwind CSS] ๐Ÿ› ๏ธํ™˜๊ฒฝ์„ค์ •

ํ•˜๋‹ˆยท2024๋…„ 8์›” 1์ผ
0

CSS ํ”„๋ ˆ์ž„์›Œํฌ

๋ชฉ๋ก ๋ณด๊ธฐ
1/4
post-thumbnail

๐Ÿ› ๏ธํ™˜๊ฒฝ์„ค์ •

์„ค์น˜

(์ถ”๊ฐ€ ์˜ˆ์ •)

tailwind.config.js ํŒŒ์ผ

content : tailwindCSS๋ฅผ ์ ์šฉํ•  ๊ฒฝ๋กœ๋“ค์„ ๋นˆ ๋ฐฐ์—ด์— ์ž…๋ ฅํ•œ๋‹ค.
์ด๋•Œ ํ”„๋กœ์ ํŠธ์—์„œ src๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด src๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ๋กœ 1๊ฐœ๋งŒ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

// tailwind.config.js

module.exports = {
  content: [
    "./app/**/*.{js,ts,jsx,tsx,mdx}",
    "./pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./components/**/*.{js,ts,jsx,tsx,mdx}",
 
    // `src` directory๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด
    "./src/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

โ—๏ธ๋‚ด๊ฐ€ ํ•„์š”ํ•œ ํŠน์ • ๊ฐ’์„ Tailwind์—์„œ ์ œ๊ณตํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ๋Œ€๊ด„ํ˜ธ[]๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํ•˜์ง€๋งŒ ํŠน์ • ๊ฐ’์ด ์—ฌ๋Ÿฌ ๋ฒˆ ๋ฐ˜๋ณต๋œ๋‹ค๋ฉด ๋ฒˆ๊ฑฐ๋กญ๋‹ค.
๐Ÿ™†๐Ÿปโ€โ™€๏ธ tailwind.config.jsํŒŒ์ผ์—์„œ theme์˜ extend, color, fontFamily์— ์ž์ฃผ ์“ฐ๋Š” ์†์„ฑ๊ณผ ๊ฐ’๋“ค์„ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

import type { Config } from 'tailwindcss'
import defaultTheme from 'tailwindcss/defaultTheme'

const config: Config = {
  content: [
    './src/pages/**/*.{js,ts,jsx,tsx,mdx}',
    './src/components/**/*.{js,ts,jsx,tsx,mdx}',
    './src/app/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  theme: {
    extend: {
      fontFamily: {
        sans: ['var(--font-pretendard)', ...defaultTheme.fontFamily.sans],
      },
      container: {
        center: true,
        padding: '24px',
        screens: {
          '2xl': '1328px',
        },
      },
      colors: {
        gray05: '#F8F9FA',
        gray10: '#F1F3F5',
        gray20: '#E9ECEF',

        content: '#F8F9FA',
        primary: '#0E1932',
        placeholder: '#ADB5BD',
        ring: '#0E1932',
        success: '#408249',
        error: '#FF5855',
      },
      flexBasis: {
        label: '150px',
      },
      minWidth: {
        label: '150px',
        orderStatusBox: '358px', // ์ฃผ๋ฌธ/๋ฐฐ์†ก/๋ฐ˜ํ’ˆ ๊ด€๋ฆฌ์˜ ์ฃผ๋ฌธ ์ฒ˜๋ฆฌํ˜„ํ™ฉ Box
        refundStatusBox: '281.6px', //์ฃผ๋ฌธ/๋ฐฐ์†ก/๋ฐ˜ํ’ˆ ๊ด€๋ฆฌ์˜ ๋ฐ˜ํ’ˆ ์ฒ˜๋ฆฌํ˜„ํ™ฉ Box
      },
      backgroundImage: {
        home: "url('/img/home-background.png')",
      },
    },
  },
  plugins: [require('@tailwindcss/forms')],
}
export default config

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

  <!-- ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๊ฐ€ ์„ค์ •๋œ ์˜์—ญ : backgroundImage์˜ home ์‚ฌ์šฉ -->
  <div class="bg-home h-64 flex items-center justify-center">
    <h1 class="text-white text-3xl">ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!</h1>
  </div>

  <!-- Flexbox ๋ ˆ์ด์•„์›ƒ : flexBasis์˜ label ์‚ฌ์šฉ -->
  <div class="flex p-4">
    <div class="flex-basis-label bg-gray30 p-4">
      ๋ ˆ์ด๋ธ” 1
    </div>
    <div class="flex-1 bg-gray10 p-4">
      ๋‚ด์šฉ 1
    </div>
    <div class="flex-basis-label bg-gray30 p-4">
      ๋ ˆ์ด๋ธ” 2
    </div>
    <div class="flex-1 bg-gray10 p-4">
      ๋‚ด์šฉ 2
    </div>
  </div>

  <!-- ์ตœ์†Œ ๋„ˆ๋น„๊ฐ€ ์„ค์ •๋œ ๋ฐ•์Šค : minWidth์˜ label ์‚ฌ์šฉ-->
  <div class="min-w-label bg-gray20 p-4">
    ์ฃผ๋ฌธ ์ƒํƒœ: ๋ฐฐ์†ก ์ค‘
  </div>

app/global.css ํŒŒ์ผ

ํŒŒ์ผ์˜ ๋งจ ์œ„์— ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ CSS์— Tailwind ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

/* global.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer : Tailwind CSS์˜ ์Šคํƒ€์ผ์„ ์—ฌ๋Ÿฌ ๋ ˆ์ด์–ด๋กœ ๋‚˜๋ˆ„์–ด ์ •์˜ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์ง€์‹œ์–ด. tailwind Base, components, utilities ๋ ˆ์ด์–ด์— ์Šคํƒ€์ผ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
@apply : Tailwind CSS์˜ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค๋ฅผ CSS ๊ทœ์น™ ๋‚ด์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์ง€์‹œ์–ด

  • ์Šคํƒ€์ผ์„ 3๊ฐœ์˜ layer๋กœ ๊ตฌ์„ฑํ•˜๋Š” ์ด์œ 
    base layer : HTML ์š”์†Œ์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ์Šคํƒ€์ผ์„ ์„ค์ •ํ•˜์—ฌ ์ผ๊ด€๋œ ์ดˆ๊ธฐ๊ฐ’ ์ œ๊ณตํ•˜๋Š” ๋ ˆ์ด์–ด
    components layer : ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ UI ๊ตฌ์„ฑ ์š”์†Œ์˜ ์Šคํƒ€์ผ์„ ์ •์˜ํ•˜๋Š” ๋ ˆ์ด์–ด ex) ๋ฒ„ํŠผ, ์นด๋“œ, ๋ชจ๋‹ฌ, ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฐ”
    utilities layer : ๊ฐœ๋ณ„ CSS ์†์„ฑ์„ ํด๋ž˜์Šค ํ˜•ํƒœ๋กœ ์ œ๊ณตํ•˜๋Š” ๋ ˆ์ด์–ด ex) text-shadow, bg-gradient

์šฐ๋ฆฌ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” components์—์„œ ๋ ˆ์ด์•„์›ƒ ์Šคํƒ€์ผ์„ ์ •์˜ํ•˜๊ณ , utilities์—์„œ ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ปดํฌ๋„ŒํŠธ ์Šคํƒ€์ผ์„ ์ ์šฉํ•œ ๊ฒƒ ๊ฐ™๋‹ค.

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  body {
    @apply bg-content;
  }

  button,
  a {
    @apply outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
  }
}

@layer components {
  .page-container {
    @apply flex w-full flex-col gap-8 bg-gray10 p-8;
  }

  .contents-container {
    @apply mt-6 flex w-full flex-col gap-6 overflow-x-auto rounded-md bg-white p-4 shadow-sm;
  }

  .side {
    @apply flex w-1/2 flex-col gap-6 p-6;
  }
}

@layer utilities {
  /* Hide scrollbar for Chrome, Safari and Opera */
  .no-scrollbar::-webkit-scrollbar {
    display: none;
  }
  /* Hide scrollbar for IE, Edge and Firefox */
  .no-scrollbar {
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
  }

  .homeBg {
    @apply bg-cover bg-center bg-no-repeat;
  }

  .eco-select {
    @apply cursor-pointer appearance-none checked:bg-green70 checked:text-green70 checked:ring-transparent;
  }

  .delivery-price {
    @apply flex h-[43px] min-w-[127px] grow items-center rounded-sm border border-gray50 bg-white;
  }

  .general-button {
    @apply rounded border border-gray70 px-4 py-2;
  }

  .second-button {
    ...
  }

  .primary-button {
    ...
  }

  .green-button {
    ...
  }

  .product-detail-input {
    @apply grow rounded border border-gray50 placeholder:text-gray50;
  }

  .contents-bg {
    @apply flex rounded-lg bg-gray10;
  }

  .orderStatusCard {
    @apply flex min-h-[164px] flex-col gap-4 rounded-lg bg-gray10 px-6 py-12;
  }
}

์ฐธ๊ณ 

Next.js์—์„œ Tailwind CSS ์‹œ์ž‘ํ•˜๊ธฐ

profile
Hi, I am HANI Developer๏ผˆโ•นโ—กโ•น๏ผ‰. .....1hani me?

0๊ฐœ์˜ ๋Œ“๊ธ€