divmagic Make design
SimpleNowLiveFunMatterSimple
Brian
Brian

DivMagic Founder

May 12, 2023

Tailwind Nneyɛe Pa - Akwankyerɛ a Etwa To ma Tailwind CSS

Image 0

Sɛ ɛba sɛ wɔde utility-first CSS bedi dwuma a, Tailwind CSS abɛyɛ go-to ano aduru ama developers pii.

Nneɛma a ɛyɛ mmerɛw, adwumayɛ, ne sɛnea ɛyɛ mmerɛw sɛ wɔde bedi dwuma no ada adi sɛ ɛsom bo kɛse wɔ nnɛyi wɛb nkɔso mu.

Nanso, te sɛ adwinnade biara no, sɛ wobɛnya mfasoɔ kɛseɛ afiri mu a, ɛho hia sɛ wobɛte Tailwind CSS nneyɛeɛ pa ase na wode adi dwuma.

Momma yɛmfa yɛn ho nhyɛ saa akwan yi bi mu.

1. Mfaso-First Fundamentals

Nyansapɛ a ɛdi kan a ɛfa mfasoɔ ho no ne nnyinasosɛm titire a ɛwɔ Tailwind CSS mu, a ne botaeɛ ne sɛ ɛbɛma developers tumi wɔ utility classes a ɛba fam mmom sen sɛ wɔde nneɛma a wɔadi kan ayɛ. Saa kwan yi betumi ayɛ te sɛ nea ɛyɛ hu mfiase no esiane sɛnea wo HTML no yɛ nsɛm pii nti; nanso, sɛ wɔte ase wie a, ɛma wotumi yɛ nhwɛsode ntɛmntɛm na wɔyɛ no sɛnea wɔyɛ no sɛnea wɔpɛ.

Wɔ utility-first architecture mu no, class biara ne style attribute pɔtee bi hyia. Sɛ nhwɛso no, text-center class no bɛma wo text no ahyia wɔ mfinimfini, bere a bg-blue-500 bɛma wo element no anya blue background sunsuma pɔtee bi.

Saa kwan yi hyɛ component reusability ho nkuran na ɛtew CSS dodow a wokyerɛw so, na eyi nsɛm a ɛtaa ba te sɛ specificity wars ne dead code elimination fi hɔ.

2. Mmuae Nsusuwii

Tailwind CSS nso di mu wɔ mmuaeɛ nhyehyɛɛ mu. Ɛde mobile-first breakpoint nhyehyɛe di dwuma, a ɛkyerɛ sɛ ɛnyɛ den sɛ ntadehyɛ ahorow a wɔde di dwuma wɔ screen nketewa so no betumi akɔ soro akɔ akɛse so. Wobetumi de prefixes a ɛnyɛ den te sɛ sm:, md:, lg:, ne xl: ayɛ eyi ansa na wo utility classes no aba.

Sɛ nhwɛso no, md:text-center de text-center adesua no bedi dwuma wɔ screen ahorow a ɛwɔ mfinimfini ne akɛse nkutoo so. Wei ma wotumi yɛ adwini a ɛyɛ mmerɛw ma screen akɛseɛ ahodoɔ, na ɛma design a ɛyɛ mmuaeɛ yɛ mframa a ɛyɛ mmerɛw wɔ Tailwind mu.

3. Styles a wɔsan de di dwuma

Bere a utility-first hyɛ nkuran sɛ wode styles bedi dwuma tẽẽ wɔ wo HTML so no, utilities a wɔaka abom a ɛyɛ den a wobɛsan ayɛ no betumi abɛyɛ den. Ɛha yi, Tailwind’s @apply akwankyerɛ no bɛyɛ nkwagyefoɔ, a ɛma wo kwan ma woyi akwan a wɔasan ayɛ no akɔ CSS adesua a wɔahyɛ da ayɛ mu.

Sɛ nhwɛsoɔ no, sɛ wotaa de bg-red-500 text-white p-6 a wɔaka abom no di dwuma a, wobɛtumi ayɛ adesua foforɔ te sɛ .error na wode @apply adi dwuma de asan de saa akwan yi adi dwuma. Eyi ma wotumi kenkan mmara no na wotumi siesie no yiye.

4. Amanneɛbɔ Styles a wode bɛka ho

Ɛwom sɛ Tailwind CSS de utility class ahorow pii ba de, nanso ebia wubehia custom styles ama ahwehwɛde pɔtee bi. Tailwind de customization options pii ma denam ne nhyehyeɛ fael, tailwind.config.js so.

Wubetumi atrɛw nhyehyɛe a wɔahyɛ da ayɛ no mu, ayɛ kɔla ahorow a wɔahyɛ da ayɛ, breakpoints, fonts, ne nea ɛkeka ho. Nanso, ɛho hia sɛ wode saa ade yi bedi dwuma kakraa bi na amma wo nhyehyɛe fael no anhyew.

5. Dwumadie & Akwankyerɛ

Tailwind CSS de dwumadie ne akwankyerɛ ahodoɔ bi ma na ama wo nkɔsoɔ suahunu no ayɛ mmerɛw. Sɛ nhwɛsoɔ no, theme() dwumadie no ma wo kwan ma wo nya wo nhyehyeɛ botaeɛ no tẽẽ wɔ wo CSS mu, na ɛma dynamic styling yɛ mmerɛ.

Bio nso, Tailwind’s akwankyerɛ, te sɛ @responsive, @variants, ne @apply, ma wo kwan ma wo yɛ responsive, state variants, na woyi styles a wɔasan ayɛ, sɛnea ɛte biara. Sɛ wode saa dwumadie ne akwankyerɛ yi di dwuma sɛdeɛ ɛfata a, ɛbɛma wo nkɔsoɔ nhyehyɛeɛ no ayɛ ntɛmntɛm na ama wo codebase no ayɛ nhyehyɛeɛ.

6. Hover, Focus, ne Tebea Afoforo a wobedi ho dwuma

Beaeɛ foforɔ a Tailwind CSS hyerɛn ne sɛ ɛdi element tebea ahodoɔ ho dwuma. Styles a wode bedi dwuma wɔ hover, focus, active, ne states afoforo so no yɛ mmerɛw te sɛ nea wode state din bɛhyɛ utility class no anim.

Sɛ nhwɛso no, hover:bg-blue-500 de bg-blue-500 adesua no bedi dwuma bere a wɔde element no ahyɛ so. Saa prefixes yi ma wo tumi a ɛkorɔn wɔ sɛnea elements yɛ wɔn ade wɔ tebea ahorow mu, na ɛma wo site no dwumadie suahunu yɛ yie.

Sɛ yɛde rewie a, Tailwind CSS nneyɛe pa yi a wobɛma wo ho akokwaw no betumi ama wo wɛb nkɔso nhyehyɛe no anya nkɔso kɛse. Ɔkwan a mfaso wɔ so kan, bere a wɔde ka ho ne ntadehyɛ ahorow a wɔsan de di dwuma yiye, nneɛma a wɔayɛ no sɛnea wɔpɛ, ne nsa a wɔde di dwuma yiye no

Fa DivMagic tu mpɔn wɔ wo Tailwind CSS adwumayɛ mu

Sɛ worehwehwɛ sɛ wobɛma wo Tailwind CSS adwumayɛ atu mpɔn a, hwɛ DivMagic, brawsa ntrɛwmu a ɛma wotumi kɔpi na wodan Tailwind CSS adesua ahorow no tẽẽ fi wo brawsa no so na ɛyɛ adwuma wɔ wɛbsaet biara so.

Chrome:Install ma Chrome

Woanya nsɛm a wɔka anaa asɛm bi? Ma yɛnfa yɛn asɛnka agua so nhu, na yebedi nea aka no ho dwuma!

Wopɛ sɛ wokɔ so yɛ nsɛm foforo?

Kɔka DivMagic email list no ho!

© 2024 DivMagic, Inc. Hokwan nyinaa wɔ hɔ.