問題
當我們考慮一個簡單的眾所周知的問題時,將「div」放在頁面的中心,這就是我們通常創建一個具有所有必要樣式的類別的方式。
<template> <div> <p>output :- </p> <p><img src="https://img.php.cn/upload/article/000/000/000/173397481225444.jpg" alt="Why add Tailwind CSS Atomic Classes to project ❓"></p> <p>Pros :- </p>
Cons :-
Building complex components from a constrained set of primitive utilities.
<template> <div > <p>Output</p> <p><img src="https://img.php.cn/upload/article/000/000/000/173397481369954.jpg" alt="Why add Tailwind CSS Atomic Classes to project ❓"></p> <p>What Happened, where are the classes ⁉️</p>
class="box-border absolute flex justify-items-center top-1-2 left-1-2 fill-gray-alpha color-fill max-w-sm"
.box-border { box-sizing: border-box; } .absolute { position: absolute; } .flex { display: flex; } .justify-items-center { justify-items: center; } .top-1-2 { top: 50% } .left-40-p { left: 40%; } .max-w-sm { max-width: 24rem; /* 384px */ }
優點
缺點
:deep() / ::v-deep
div { ::v-deep .center-div { background-color: red; } }
div { ::v-deep :first-of-type { background-color: red; } }
Tailwind 安裝
npm install -D tailwindcss npx tailwindcss init
當您的應用程式已經有一個現有的 css 程式庫時,最好選擇我們需要的類別並將它們新增至 css 檔案中,然後在應用程式中全域註冊。
假設您的應用程式只需要 Flexbox 樣式的彈性
-- 從 Flex 樣式中取得您需要的類別清單
櫻桃選課嗎?認為 ?您的應用程式需求,並根據需要添加它們。
透過這種方式,我們可以保持 CSS 套件很小,但開發團隊需要嚴格控制他們應用的 CSS? .
/* FlexBox */ .flex { display: flex; } .flex-row { flex-direction: row; } .flex-row-reverse { flex-direction: row-reverse; } .flex-col { flex-direction: column; } .flex-col-reverse { flex-direction: column-reverse; } .flex-wrap { flex-wrap: wrap; } .flex-nowrap { flex-wrap: nowrap; } .grow { flex-grow: 1; } .grow-0 { flex-grow: 0; } .shrink { flex-shrink: 1; } .shrink-0 { flex-shrink: 0; } .justify-normal { justify-content: normal; } .justify-start { justify-content: flex-start; } .justify-end { justify-content: flex-end; } .justify-center { justify-content: center; } .justify-between { justify-content: space-between; } .justify-around { justify-content: space-around; } .justify-evenly { justify-content: space-evenly; } .justify-stretch { justify-content: stretch; } .justify-items-start { justify-items: start; } .justify-items-end { justify-items: end; } .justify-items-center { justify-items: center; } .justify-items-stretch { justify-items: stretch; } .justify-self-auto { justify-self: auto; } .justify-self-start { justify-self: start; } .justify-self-end { justify-self: end; } .justify-self-center { justify-self: center; } .justify-self-stretch { justify-self: stretch } .content-noraml { align-content: normal; } .content-center { align-content: center; } .content-start { align-content: start; } .content-end { align-content: end; } .content-between { align-content: space-between; } .content-around { align-content: space-around; } .content-evenly { align-content: space-evenly; } .content-baseline { align-content: baseline; } .content-stretch { align-content: stretch; } .items-start { align-items: start; } .items-end { align-items: end; } .items-center { align-items: center; } .items-baseline { align-items: baseline; } .items-stretch { align-items: stretch; } // Align Self .self-auto { align-self: auto; } .self-start { align-self: flex-start; } .self-end { align-self: flex-end; } .self-center { align-self: center; } .self-stretch { align-self: stretch; } .self-baseline { align-self: baseline; }
結論
以上是為什麼要將 Tailwind CSS 原子類別加入到專案中❓的詳細內容。更多資訊請關注PHP中文網其他相關文章!