Laurence R.
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    <center><img src="https://blog.nashtechglobal.com/wp-content/uploads/2025/08/O-que-e-Tailwind-CSS-e-por-que-ele-virou-tendencia-no-front-end_-Programadores-Depre-Programacao-e-Tecnologia.jpeg" /></center> 前言 --- 我們在寫網頁切版的時候,最常接觸到的就是 CSS。 一般來講,我們可能會這樣寫: * 先在 HTML 中寫一個結構: ```html= <div class="user-profile-card"> <img src="..." alt="..." class="profile-avatar"> <h3 class="user-name">Gemini</h3> <p class="user-bio">一個由 Google 打造的 AI 助手...</p> <button class="follow-button">Follow</button> </div> ``` * 跳到 <code>.css</code> 檔案,開始定義每個 class: ```CSS .user-profile-card { background-color: white; border-radius: 8px; padding: 16px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .profile-avatar { width: 50px; height: 50px; border-radius: 9999px; /* 圓形 */ } .user-name { font-size: 1.25rem; font-weight: 600; /* 粗體 */ } .follow-button { background-color: #3b82f6; /* 藍色 */ color: white; padding: 8px 16px; } .follow-button:hover { background-color: #2563eb; /* 深一點的藍色 */ } ``` **這樣子寫的話會遇到幾個 「痛點」:** * **命名地獄:** 你要花很多時間去想 class 名字 (`.user-profile-card`, `.follow-button-primary`...)。當專案變大,命名衝突和管理就變成一場惡夢。 * **檔案切換:** 你必須不斷在 HTML 和 CSS 兩個檔案之間來回切換,打斷心流。 * **CSS 檔案膨脹:** 你寫了很多 CSS,但時間一久,你根本不敢刪掉舊的 class,因為你不確定刪掉它會不會弄壞網站的其他地方。 * **一致性問題:** A 頁面的按鈕 `padding` 是 `8px`,B 頁面可能是 `10px`。A 頁面的卡片陰影是 `0.1`,B 頁面是 `0.15`。設計風格很難統一。 **Tailwind CSS 就是為了解決這些問題而生的。** 它不是要你 _取代_ CSS,而是提供一種 _不同_ 的方式來 _使用_ CSS。 它提供給你一大堆「**工具**」,讓你直接在 HTML 裡「**組合**」出你想要的樣子。 核心概念 (一) - Utility-First (工具優先) --- * 這是 Tailwind 最核心的概念。它不提供像是 BootStrap(UI 庫) 預先做好的元件(像 `Card` 或 `Button`)。 * 相反地,它提供的是「**單一用途的工具 class**」。 * 例如: * `p-4` 代表 `padding: 16px;` (1rem) * `bg-white` 代表 `background-color: white;` * `rounded-lg` 代表 `border-radius: 8px;` * `shadow-md` 代表 `box-shadow: (某個中等陰影值);` * `text-xl` 代表 `font-size: 1.25rem;` * `font-bold` 代表 `font-weight: 700;` * 所以,前面那個卡片用 Tailwind 寫,會變成這樣: ```html= <div class="bg-white rounded-lg p-4 shadow-md"> <img src="..." alt="..." class="w-12 h-12 rounded-full"> <h3 class="text-xl font-bold">Gemini</h3> <p class="text-gray-600">一個由 Google 打造的 AI 助手...</p> <button class="bg-blue-500 text-white py-2 px-4 rounded">Follow</button> </div> ``` * **優點:** 你不用再想 class 名字,也不用切換檔案。所有的樣式都在 HTML 裡,一目了然。 核心概念 (二) - Mobile-First (行動優先的響應式設計) --- 我們會去用不同的裝置去瀏覽網頁,常見的像是用手機、平板與電腦。而因為這三種裝置的螢幕大小不同,我們需要網頁有 **RWD (響應式設計的功能)**,而實現這個功能,如果使用傳統的 CSS 去實現的話,會使檔案變得非常巨大。 * Tailwind 預設的樣式是給手機看的。如果你想在「平板」或「電腦」上改變樣式,你只要加上「前綴」 (Prefix)。 * 例如:`sm:` (小螢幕), `md:` (中螢幕), `lg:` (大螢幕), `xl:` (超大螢幕)。 * **範例:** 一個區塊,在手機上是「寬度 100%」,但在中等螢幕(md)以上,變成「寬度 50%」。 ```html= <!-- 在手機上是寬度 100%,螢幕尺寸超過 md (中等螢幕) 以上,變成寬度 50% --> <div class="w-full md:w-1/2"> ... </div> ``` **範例:** 手機上文字置中,電腦上文字靠左。 ```html= <div class="text-center lg:text-left"> ... </div> ``` 核心概念 (三) - State Variants (狀態變化) --- * 像是 `hover` (滑鼠懸停)、`focus` (選取)、`disabled` (禁用) 等狀態,也可以用「前綴」輕易做到。 * **範例:** 一個按鈕,平常是藍色,滑鼠移上去 (hover) 變成深藍色。 ```html= <button class="bg-blue-500 hover:bg-blue-700 text-white ..."> Click me </button> ``` 核心概念 (四) - JIT (Just-In-Time) Engine --- 看到這邊有人可能會問:「哇,那這樣 Tailwind CSS 提供幾千個 class,我的 CSS 檔案會不會大到爆啊?」 其實並不會。 JIT 引擎會去掃描我們所有的 HTML 與 JS 檔案,然後找出我們「真正有用到」的 class。 像是我如果只用到 <code>p-4</code>,那它就只會把這個 class 生成到最終的 CSS 檔案中,所以其實最後的 CSS 檔案通常都蠻小的。 核心概念 (五) - Design System (可客製化的設計系統) --- * Tailwind 已經幫你定義好一套「設計系統」。 * 例如 `p-1` (4px), `p-2` (8px), `p-3` (12px), `p-4` (16px)... 它的間距是有規律的。 * 它的顏色 `blue-100` (最淺), `blue-500` (中等), `blue-900` (最深) 也是配好的。 * 這強迫團隊在開發時使用「**一致**」的間距和顏色,讓網站風格更統一。 * (進階) 如果你需要客製化(例如公司的主色是 `#FF6600`),你都可以在 `tailwind.config.js` 檔案中輕鬆設定。 --- 參考文件:https://tailwindcss.com/docs/installation/using-vite

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully