検索
ホームページウェブフロントエンドCSSチュートリアルTailwind CSS Atomic クラスをプロジェクトに追加する理由 ❓

問題

  • 多くの UI 開発者が参加するプロジェクトでは、必要に応じてそれぞれが独自のカスタム CSS クラスを宣言して、独自の方法でコンポーネントのコーディングを開始します。

伝統的な方法

ページ内で「div」を中央に配置するというよく知られた簡単な問題を考えるとき、これが通常、必要なスタイルをすべて備えたクラスを作成する方法です。

<template>
    <div>



<p>output :- </p>

<p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173397481225444.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="Why add Tailwind CSS Atomic Classes to project ❓"></p>

<p>Pros :- </p>

<ul>
<li>Developers can add any styling for the classes as they please. </li>
</ul>

<p>Cons :- </p>

<ul>
<li>As project grows, there won't be any uniformed styling for the project. </li>
<li>It becomes tedious to apply same styles for new modules, as develepoers need to apply them themselves. </li>
<li>Developer intent is not clear, i.e class name is "center-div" but inner styling can be anything they desire. </li>
</ul>

<h3>
  
  
  Tailwind philosophy
</h3>

<blockquote>
<p>Building complex components from a constrained set of primitive utilities.</p>
</blockquote>

<ul>
<li>We need to break a component classes from group up with Atomic classes.
</li>
</ul>

<pre class="brush:php;toolbar:false"><template>
    <div>



<p>Output</p>

<p><img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173397481369954.jpg?x-oss-process=image/resize,p_40" class="lazy" alt="Why add Tailwind CSS Atomic Classes to project ❓"></p>

<p>What Happened, where are the classes ⁉️</p>

<ul>
<li>As you can see from the code above we have used quite a few classes in our "div"</li>
</ul>

<blockquote>
<p>class="box-border absolute flex justify-items-center top-1-2 left-1-2 fill-gray-alpha color-fill max-w-sm"</p>
</blockquote>

<ul>
<li>Each class is registered in the global application scope, which goes like this
</li>
</ul>

<pre class="brush:php;toolbar:false">.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 */
}
  • これらのクラスはすべてグローバル スコープで利用できるため、開発者は誰でも自由に使用できます。

長所

  • CSS バンドルのサイズを大幅に削減します。
  • コンポーネントのスタイルがチーム全体で一貫していることを保証します。
  • 開発者は、同じスタイルをやり直す手間が少なく、アイデアのプロトタイプを迅速に作成できます。

短所

  • 学習曲線では、各開発者は既存のクラスに慣れる必要があります。
  • プロジェクトは、他の人が使用できるようにこれらのグローバルに宣言されたクラスを追加するとき、適切なドキュメントを保管する必要があります。

Vue JS の落とし穴

:deep() / ::v-deep

  • ベイン? Vue JS CSS ターゲティングの。

伝統的なクラス

  • クラスのターゲット設定とスタイルの適用は非常に簡単です
div {
    ::v-deep .center-div {
        background-color: red;
    }
}

対風クラス

  • 開発者は、「div」をターゲットにする場合、非常に創造性を発揮する必要があります。
div {
    ::v-deep :first-of-type {
        background-color: red;
    }
}

Tailwind CSS クラスをアプリケーションに導入する方法

伝統的な方法

  • これらは
  • で簡単にインストールできます

Tailwind インストール

npm install -D tailwindcss
npx tailwindcss init
  • しかし、これにより、グローバル スコープ内に大量のすべてのクラスがインストール (つまり、登録) されます。

型破り?方法

  • アプリケーションに既存の CSS ライブラリがある場合は、必要なクラスを厳選して 1 つの CSS ファイルに追加し、アプリ内でグローバルに登録することが理想的です。

  • アプリケーションがフレックスボックス スタイルの柔軟性のみを必要としているとします
    -- フレックス スタイルから必要なクラスのリストを取得します

  • クラスを選んでみてはいかがですか?仮定する ?アプリケーションが必要とするものを選択し、必要に応じて追加します。

  • この方法により、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 で Atomic クラスを参照として使用すると、
  • プロジェクトの CSS フットプリントを削減します。
  • アプリケーション全体でスタイルの一貫性を維持します。
  • 迅速なプロトタイピングにより、開発者の速度が向上します。 ?

以上がTailwind CSS Atomic クラスをプロジェクトに追加する理由 ❓の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
非常に多くの色のリンク非常に多くの色のリンクApr 13, 2025 am 11:36 AM

最近の色に関するツール、記事、リソースの実行がありました。あなたの楽しみのためにここにそれらを丸くすることで、私がいくつかのタブを閉じてもらいましょう。

FlexBoxでの自動マージンの仕組みFlexBoxでの自動マージンの仕組みApr 13, 2025 am 11:35 AM

ロビンは以前にこれをカバーしたことがありますが、私は過去数週間でそれについての混乱を聞いて、他の人がそれを説明することに刺されたのを見ました、そして私は望んでいました

動く虹色の下線動く虹色の下線Apr 13, 2025 am 11:27 AM

サンドイッチサイトのデザインが大好きです。多くの美しい特徴の中には、これらの見出しがあり、レインボーの下線が下線を描いて、スクロールするときに動きます。そうではありません

新年、新しい仕事?グリッド駆動の履歴書を作成しましょう!新年、新しい仕事?グリッド駆動の履歴書を作成しましょう!Apr 13, 2025 am 11:26 AM

多くの人気のある履歴書設計は、グリッド形状にセクションを配置することにより、利用可能なページスペースを最大限に活用しています。 CSSグリッドを使用して、レイアウトを作成しましょう

リロードしすぎるという習慣からユーザーを分解する1つの方法リロードしすぎるという習慣からユーザーを分解する1つの方法Apr 13, 2025 am 11:25 AM

ページのリロードは何かです。ページが反応しないと思われるとき、または新しいコンテンツが利用可能であると信じるときにページを更新することもあります。時々私たちはただ怒っています

Reactを使用したドメイン駆動型のデザインReactを使用したドメイン駆動型のデザインApr 13, 2025 am 11:22 AM

Reactの世界でフロントエンドアプリケーションを整理する方法に関するガイダンスはほとんどありません。 (「正しいと感じる」までファイルを移動するだけです笑)。真実

非アクティブユーザーの検出非アクティブユーザーの検出Apr 13, 2025 am 11:08 AM

ほとんどの場合、ユーザーがアプリケーションに積極的に関与しているのか、一時的に非アクティブであるかを本当に気にしません。非アクティブ、意味、おそらく彼ら

Wufoo ZapierWufoo ZapierApr 13, 2025 am 11:02 AM

Wufooは常に統合に優れています。キャンペーンモニター、MailChimp、TypeKitなどの特定のアプリと統合されていますが、

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません