[WebUI]Tailwind + nextjs(button) – 1

๐Ÿ‘‰๐Ÿป ์›นํŽ˜์ด์ง€๋ฅผ ํ™”๋ฉด์— ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด์„œ HTML์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
HTML is used to display web pages on the screen.

๐Ÿ‘‰๐Ÿป ์ด ์›นํŽ˜์ด์ง€๋ฅผ ์Šคํƒ€์ผ๋ง ํ•˜๊ธฐ์œ„ํ•ด์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ css๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
CSS is primarily used to style this webpage.

๐Ÿ‘‰๐Ÿป ์›นํŽ˜์ด์ง€ ์Šคํƒ€์ผ๋ง์„ ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋ณธ css์ฝ”๋“œ๊ฐ€ ๋„ˆ๋ฌด ๊ธธ๊ธฐ ๋•Œ๋ฌธ์— tailwindcss๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์ฝ”๋“œ๊ฐ€ ๋” ์งง์•„์ง‘๋‹ˆ๋‹ค.
Standard CSS code for styling web pages can be quite lengthy, whereas using Tailwind CSS allows you to implement the same functionality with less code.

๐Ÿ‘‰๐Ÿป tailwind๋Š” ์‹คํ–‰์†๋„๊ฐ€ ๋น ๋ฅด๊ณ  ๋‹คํฌ๋ชจ๋“œ๋“ฑ์˜ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ๊ฐ€ ํ›จ์”ฌ ์šฉ์ดํ•ฉ๋‹ˆ๋‹ค.
Tailwind offers fast execution speeds and makes it much easier to implement features like dark mode.

๐Ÿ‘‰๐Ÿป ์ด ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ํ…์ŠคํŠธ์™€ ๊ฐ„๋‹จํ•œ ๋ฒ„ํŠผ์„ css์™€ tailwindcss๋กœ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.
In this project, text and simple buttons are implemented using CSS and Tailwind CSS.

๐Ÿ‘‰๐Ÿป Nextjsํ”„๋กœ์ ํŠธ ์ƒ์„ฑ์€ ์ด ํฌ์ŠคํŠธ์˜ ๊ฐ€์žฅ ์•„๋ž˜ ๋ถ€๋ถ„์„ ์ฐธ์กฐํ•˜์„ธ์š”
Please refer to the bottom of this post for instructions on creating a Next.js project.

๐Ÿ‘‰๐Ÿป ์ „์ฒด ์ฝ”๋“œ๋Š” ๊นƒํ—ˆ๋ธŒ์—์„œ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
You can find the full code on GitHub.

https://github.com/gideonslife01/flm-webui


๐Ÿ“ ํ…์ŠคํŠธ / Text

โœ”๏ธ tailwincss์‚ฌ์šฉํ•˜๋ ค๋ฉด ๊ธฐ๋ณธ ์›นํŽ˜์ด์ง€์— ์•ˆ์˜ HTML ํƒœ๊ทธ์— tailwindcss๋ฅผ ๋‹ค์Œ์ฒ˜๋Ÿผ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.
To use Tailwind CSS, apply it to the HTML tags within your web page as follows.

<p className="mt-4 text-sm text-gray-400">Next.js + Tailwind CSS</p>

1) mt-4 :

— ๊ณต์‹๋ฌธ์„œ/Official Documentation

https://tailwindcss.com/docs/margin#adding-margin-to-a-single-side

A. ์ปดํฌ๋„ŒํŠธ ์œ„์ชฝ์— 4๋งŒํผ์˜ ์—ฌ๋ฐฑ์„ ํ™•๋ณดํ•ฉ๋‹ˆ๋‹ค.
Leave a margin of 4 above the component.

B. mt์˜†์˜ ์ˆซ์ž๋Š” ์•„๋ž˜์˜ ํ‘œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”
Please refer to the table below for the numbers next to ‘mt’.

ํด๋ž˜์Šค / Classrempx
mt-10.25rem4px
mt-20.5rem8px
mt-30.75rem12px
mt-41rem16px
mt-61.5rem24px
mt-82rem32px

2) text-sm :

— ๊ด€๋ จ ๋ฌธ์„œ / Official Documents

https://tailwindcss.com/docs/font-size#basic-example

A.๊ธ€์žํฌ๊ธฐ๋ฅผ 14px๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

B.text์˜†์˜ ๋ฌธ์ž๋Š” ์•„๋ž˜์˜ ํ‘œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”
Please refer to the table below for the characters next to the text.

ํด๋ž˜์Šค/Classrempxline-height
text-xs0.75rem12px16px
text-sm0.875rem14px20px
text-base1rem16px24px – ๊ธฐ๋ณธ๊ฐ’/default value
text-lg1.125rem18px28px
text-xl1.25rem20px28px

3)text-gray-400 :

— ๊ด€๋ จ๋ฌธ์„œ / Official Documents

https://tailwindcss.com/docs/colors#using-color-utilities

A.๊ธ€์ž ์ƒ‰์€ ํšŒ์ƒ‰์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ์ง„ํ•˜๊ธฐ๋Š” 400์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
Set the text color to gray and the weight to 400.

B.์ˆซ์ž์— ๋ถ€๋ถ„์€ ์•„๋ž˜์˜ ์„ค๋ช…์„ ์ฐธ์กฐํ•˜์„ธ์š”
Please refer to the explanation below regarding the numbers.

text-gray-50
 - ์•„์ฃผ ์—ฐํ•œ ํšŒ์ƒ‰ / Very light gray

text-gray-200
 - ์—ฐํ•œ ํšŒ์ƒ‰ / Light gray

text-gray-400
 - ์•ฝ๊ฐ„ ์—ฐํ•œ ํšŒ์ƒ‰  / A slightly light gray - #9ca3af

text-gray-600
 - ์ง„ํ•œ ํšŒ์ƒ‰ / Dark gray

text-gray-900 
- ์•„์ฃผ ์ง„ํ•œ ํšŒ์ƒ‰ / Very dark gray

โœ”๏ธ ๊ธฐ๋ณธ CSS์—์„œ๋Š” ์œ„์˜ ์ฝ”๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
Implementing the code above using standard CSS results in the following:

 <p className="helper">Next.js + Pure CSS</p>
     <style>{` ...
        .helper {
          margin-top: 16px;
          font-size: 14px;
          color: #9ca3af;
        }
      `}</style>

๐Ÿ’ก ๊ณต์‹๋ฌธ์„œ๋Š” tailwind.com์˜ ๊ฒ€์ƒ‰์„ ํ™œ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
You can find official documents by using the search function on tailwind.com.

๐Ÿ“ ๋ฒ„ํŠผ / Button

โœ”๏ธ tailwindcss๋ฅผ ๋ฒ„ํŠผ์— ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
The code for applying Tailwind CSS to a button is as follows.

โœ”๏ธ ๋ฒ„ํŠผ ํ…์ŠคํŠธ๋Š” “tailwind ์‹œ์ž‘ํ•˜๊ธฐ/Start”๊ฐ€ ํ™”๋ฉด์— ํ‘œ์‹œ๋˜๊ณ  ๋ฒ„ํŠผ ํด๋ฆญ์‹œ “ํด๋ฆญ๋จ/Clicked”๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.
The button displays “tailwind ์‹œ์ž‘ํ•˜๊ธฐ/Start,” and changes to “ํด๋ฆญ๋จ/Clicked” when clicked.

      <button
        onClick={handleClick}
        className="px-6 py-3 bg-blue-500 text-white rounded-xl font-bold shadow-md hover:bg-blue-600 hover:-translate-y-0.5 active:scale-95 transition-all"
      >
        {clicked ? 'ํด๋ฆญ๋จ/Clicked ๐ŸŽ‰' : 'tailwind ์‹œ์ž‘ํ•˜๊ธฐ/Start'}
      </button>

1) ์œ„์˜ ์ฝ”๋“œ์— ๋Œ€ํ•œ ์„ค๋ช…์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
An explanation of the code above is provided below.

1. ํฌ๊ธฐ (์—ฌ๋ฐฑ) / Size (Margins)

px-6  
- ์ขŒ์šฐ ์•ˆ์ชฝ ์—ฌ๋ฐฑ 24px (6 * 4px)
Left and right inner margins: 24px (6 ร— 4px)

py-3  
- ์œ„์•„๋ž˜ ์•ˆ์ชฝ ์—ฌ๋ฐฑ 12px (3 * 4px)
Top and bottom inner margins: 12px (3 ร— 4px)

2. ์ƒ‰ / Color

bg-blue-500 
- ๋ฐฐ๊ฒฝ์ƒ‰ ํŒŒ๋ž€์ƒ‰ ์ง„ํ•˜๊ธฐ ์ค‘๊ฐ„ ์ •๋„ (#3b82f6)
Background color: blue, medium intensity.

text-white
- ๊ธ€์ž์ƒ‰ ํฐ์ƒ‰
Text color: white

3. ๋ชจ์–‘ / shape

rounded-xl
- ๋ชจ์„œ๋ฆฌ ๋‘ฅ๊ธ€๊ฒŒ 12px
Rounded corners 12px

font-bold
- ๊ธ€์ž ๋‘๊ป˜ 700 (๊ตต๊ฒŒ)
Font weight 700 (Bold)

shadow-md
- ๊ทธ๋ฆผ์ž ์ค‘๊ฐ„ ํฌ๊ธฐ
Medium-sized shadow

4. ์ƒํ˜ธ์ž‘์šฉ / Interaction

hover:bg-blue-600
- ๋งˆ์šฐ์Šค ์˜ฌ๋ฆฌ๋ฉด ๋ฐฐ๊ฒฝ์ƒ‰ ๋” ์ง„ํ•œ ํŒŒ๋ž‘์œผ๋กœ
Change the background color to a darker blue on hover.

hover:-translate-y-0.5
- ๋งˆ์šฐ์Šค ์˜ฌ๋ฆฌ๋ฉด 2px ์œ„๋กœ ์‚ด์ง ๋œธ (-0.5 = -2px)
Hovers up by 2px (-0.5 = -2px)

active:scale-95
- ํด๋ฆญํ•˜๋Š” ์ˆœ๊ฐ„ 95% ํฌ๊ธฐ๋กœ ์‚ด์ง ์ž‘์•„์ง
It shrinks slightly to 95% of its size the moment you click it.

transition-all 
- ์œ„ ๋ณ€ํ™”๋“ค์„ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์• ๋‹ˆ๋ฉ”์ด์…˜์œผ๋กœ
Smoothly animate the above changes

โœ”๏ธ ๊ธฐ๋ณธ CSS์—์„œ๋Š” ์œ„์˜ ๋ฒ„ํŠผ ์ฝ”๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
Implementing the button code above with basic CSS results in the following.

... ... 
        <button
          onClick={handleClick}
          className="btn-primary"
        >
          {clicked ? 'ํด๋ฆญ๋จ/Clicked ๐ŸŽ‰' : 'CSS ์‹œ์ž‘ํ•˜๊ธฐ/Start'}
        </button>
... ...
      <style>{`
         /* ๋ฒ„ํŠผ ๊ธฐ๋ณธ / Button Basic */
        .btn-primary {
          padding: 12px 24px;
          background-color: #3b82f6;
          color: white;
          border-radius: 12px;
          font-weight: 700;
          font-size: 16px;
          border: none;
          cursor: pointer;
          box-shadow: 0 4px 6px rgba(0,0,0,0.1);
          transition: all 0.2s ease;
        }
        /* ๋ฒ„ํŠผ ๋งˆ์šฐ์Šค ์˜ค๋ฒ„ / Button mouseover */
        .btn-primary:hover {
          background-color: #2563eb;
          transform: translateY(-2px);
          box-shadow: 0 6px 10px rgba(0,0,0,0.15);
        }
        /* ๋ฒ„ํŠผ ํด๋ฆญ / Button active */
        .btn-primary:active {
          transform: scale(0.95);
        }
        /* ๋ฒ„ํŠผ ํ•˜๋‹จ ํ…์ŠคํŠธ / Text below the button */
        .helper {
          margin-top: 16px;
          font-size: 14px;
          color: #9ca3af;
        }
      `}</style>
... ...

โœ”๏ธ ๋‚˜๋จธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ ์ž…๋‹ˆ๋‹ค.
The rest are containers.

— tailwind

<main className="min-h-screen flex flex-col items-center justify-center bg-gray-50"> ... ... </main>

1)tailwind์ฝ”๋“œ ์„ค๋ช…์ž…๋‹ˆ๋‹ค.
Here is an explanation of the Tailwind code.

1. min-h-screen
- ํ™”๋ฉด ๋†’์ด๋งŒํผ ์ตœ์†Œ ๋†’์ด๋ฅผ ํ™•๋ณด, ๋‚ด์šฉ์ด ์ ์–ด๋„ ํ™”๋ฉด ๊ฝ‰ ์ฐจ๊ฒŒ.
Ensure a minimum height equal to the screen height so that the content fills the screen, even if there is little content.

2. flex 
- ํ”Œ๋ ‰์Šค ๋ชจ๋“œ ์ผœ๊ธฐ
Turn on Flex mode

display: flex
- ์ž์‹ ์š”์†Œ๋“ค์„ ์œ ์—ฐํ•˜๊ฒŒ ๋ฐฐ์น˜ํ•˜๋Š” ๋ชจ๋“œ. ์ด๊ฑธ ์ผœ์•ผ ์•„๋ž˜ ์ •๋ ฌ ๋ช…๋ น๋“ค ์‚ฌ์šฉ๊ฐ€๋Šฅ ํ•จ.
A mode for flexibly arranging child elements. You must enable this to use the alignment commands below.

3. flex-col 
- ์ž์‹ ์ปดํฌ๋„ŒํŠธ๋“ค์˜ ๋ฐฉํ–ฅ
Orientation of child components
- flex-direction: column
- ์ž์‹๋“ค์„ ์„ธ๋กœ๋กœ ์Œ“๊ธฐ (๋ฒ„ํŠผ ์œ„์— ํ…์ŠคํŠธ ์•„๋ž˜ ๊ฐ™์€ํ˜•์‹) ์•ˆ ์“ฐ๋ฉด ๊ธฐ๋ณธ์€ ๊ฐ€๋กœ(row).
If you don't specify otherwise, the default layout for children is horizontal (row); stacking them vertically (e.g., text below a button) requires a different setting.

4. items-center 
- ๊ฐ€๋กœ(์ขŒ์šฐ) ์ค‘์•™ ์ •๋ ฌ
Horizontal (left-right) center alignment
- align-items: center
- ์„ธ๋กœ๋กœ ์Œ“์˜€์„ ๋•Œ๋Š” ์ขŒ์šฐ๋ฅผ ๊ฐ€์šด๋ฐ๋กœ ์ •๋ ฌ
When stacked vertically, center the left and right sides.
- flex-col์ผ ๋•Œ ์ขŒ์šฐ ์ค‘์•™ ์ •๋ ฌ ๋‹ด๋‹น
Handles horizontal centering when using flex-col.

5. justify-center 
- ์„ธ๋กœ(์œ„์•„๋ž˜) ์ค‘์•™ ์ •๋ ฌ
Vertical (top-to-bottom) center alignment
- justify-content: center
- ์„ธ๋กœ๋กœ ์Œ“์˜€์„ ๋•Œ๋Š” ์œ„์•„๋ž˜๋ฅผ ๊ฐ€์šด๋ฐ๋กœ ์ •๋ ฌ
When stacked vertically, center the top and bottom.
- items-center + justify-center ๊ฐ™์ด ์“ฐ๋ฉด ์ •๊ฐ€์šด๋ฐ ์ •๋ ฌ
Use `items-center` and `justify-center` together to center-align perfectly.

6. bg-gray-50 
- ๋ฐฐ๊ฒฝ์ƒ‰
background color
- background-color: #f9fafb
- ์•„์ฃผ ์—ฐํ•œ ํšŒ์ƒ‰. 
A very pale gray.

— css

<main className="wrapper"> ... ... </main>
 <style>{` 
        /* ์ปจํ…Œ์ด๋„ˆ / Container */
        .wrapper {
          width: 100%;
          min-height: 100vh;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          background-color: #f9fafb;
        }
`}</style>

๐Ÿ“ Nextjs ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ / Create a Next.js project

โœ”๏ธ nextjsํ”„๋กœ์ ํŠธ๋ฅผ ํ„ฐ๋ฏธ๋„์—์„œ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

npx create-next-app@latest

โœ”๏ธ ์•„๋ž˜์ฒ˜๋Ÿผ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ Nextjs๋ฅผ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์น˜ํ•˜๋ฉด tailwindcss๊ฐ€ ์ž๋™์œผ๋กœ ์„ค์น˜๋ฉ๋‹ˆ๋‹ค.

WebUI % npx create-next-app@latest
โœ” What is your project named? โ€ฆ tailwindcss-nextjs
โœ” Would you like to use the recommended Next.js defaults? โ€บ Yes, use recommended defaults
Creating a new Next.js app in /Users/... .../tailwindcss-nextjs.

Using npm.

Initializing project with template: app-tw 


Installing dependencies:
- next
- react
- react-dom

Installing devDependencies:
- @tailwindcss/postcss
- @types/node
- @types/react
- @types/react-dom
- eslint
- eslint-config-next
- tailwindcss
- typescript


๐Ÿ“ ํ…Œ์ŠคํŠธ / Test

โœ”๏ธ tailwind button

tailwindcss

โœ”๏ธ css button

CSS

์š”ํ•œ๋ณต์Œ 8์žฅ 32์ ˆ / John 8:32

“๊ทธ๋ฆฌ๊ณ  ๋„ˆํฌ๋Š” ์ง„๋ฆฌ๋ฅผ ์•Œ๊ฒŒ ๋  ๊ฒƒ์ด๋ฉฐ, ์ง„๋ฆฌ๊ฐ€ ๋„ˆํฌ๋ฅผ ์ž์œ ๋กญ๊ฒŒ ํ•  ๊ฒƒ์ด๋‹ค.”

“Then you will know the truth ,and the truth will set you free”

Leave a Reply