• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

Utilizing CSS Cascade Layers With Tailwind Utilities

Admin by Admin
July 1, 2025
Home Coding
Share on FacebookShare on Twitter


Adam Wathan has (very cleverly) constructed Tailwind with CSS Cascade Layers, making it extraordinarily highly effective for organizing kinds by precedence.

@layer theme, base, parts, utilities;
@import 'tailwindcss/theme.css' layer(theme);
@import 'tailwindcss/utilities.css' layer(utilities);

The core of Tailwind are its utilities. This implies you might have two decisions:

  1. The default selection
  2. The unorthodox selection

The default selection

The default selection is to observe Tailwind’s really helpful layer order: place parts first, and Tailwind utilities final.

So, if you happen to’re constructing parts, you must manually wrap your parts with a @layer directive. Then, overwrite your part kinds with Tailwind, placing Tailwind because the “most necessary layer”.

/* Write your parts */
@layer parts {
  .part {
    /* Your CSS right here */
  }
}
 

...

That’s an honest approach of doing issues.

However, being the dangerous boy I’m, I don’t take the default method because the “finest” one. Over a yr of (main) experimentation with Tailwind and vanilla CSS, I’ve come throughout what I consider is a greater answer.

The Unorthodox Alternative

Earlier than we go on, I’ve to let you know that I’m writing a course known as Unorthodox Tailwind — this reveals you every thing I learn about utilizing Tailwind and CSS in synergistic methods, leveraging the strengths of every.

Shameless plug apart, let’s dive into the Unorthodox Alternative now.

On this case, the Unorthodox Alternative is to jot down your kinds in an unnamed layer — or any layer after utilities, actually — in order that your CSS naturally overwrites Tailwind utilities.

Of those two, I choose the unnamed layer choice:

/* Unnamed layer choice */
@layer theme, base, parts, utilities; 

/* Write your CSS usually right here */ 
.part { /* ... */ }
/* Named layer choice */
/* Use no matter layer title you give you. I merely used css right here as a result of it made most sense for explaining issues */
@layer theme, base, parts, utilities, css; 

@layer css {
  .part { /* ... */ }
}

I’ve many the reason why I do that:

  1. I don’t like so as to add pointless CSS layers as a result of it makes code tougher to jot down — extra keystrokes, having to recollect the particular layer I used it in, and many others.
  2. I’m fairly expert with ITCSS, selector specificity, and all of the good-old-stuff you’d anticipate from a seasoned front-end developer, so writing CSS in a single layer doesn’t scare me in any respect.
  3. I can do complicated stuff which can be exhausting or inconceivable to do in Tailwind (like theming and animations) in CSS.

Your mileage might range, after all.

Now, if in case you have adopted my reasoning up to now, you’d have observed that I exploit Tailwind very otherwise:

  • Tailwind utilities usually are not the “most necessary” layer.
  • My unnamed CSS layer is a very powerful one.

I do that so I can:

  • Construct prototypes with Tailwind (shortly, simply, particularly with the instruments I’ve created).
  • Shift these properties to CSS once they get extra complicated — so I don’t should learn messy utility-littered HTML that makes my coronary heart sink. Not as a result of utility HTML is dangerous, however as a result of it takes numerous mind processing energy to determine what’s occurring.

Lastly, right here’s the good factor about Tailwind being in a utility layer: I can at all times !necessary a utility to present it energy.


...

Whoa, maintain on, wait a minute! Isn’t this fallacious, you may ask?

Nope. The !necessary key phrase has historically been used to override courses. On this case, we’re leveraging on the !necessary function in CSS Layers to say the Tailwind utility is extra necessary than any CSS within the unnamed layer.

That is completely legitimate and is a built-in function for CSS Layers.

Moreover, the !necessary is so express (and used so little) that it is sensible for one-off quick-and-dirty changes (with out making a model new selector for it).

Tailwind utilities are extra highly effective than they appear

Tailwind utilities usually are not a 1:1 map between a category and a CSS property. Constructed-in Tailwind utilities principally appear to be this so it can provide folks a fallacious impression.

Tailwind utilities are extra like handy Sass mixins, which suggests we are able to construct efficient instruments for layouts, theming, typography, and extra, via them.

You will discover out about these ideas inside Unorthodox Tailwind.

Thanks for studying and I hope you’re having fun with a brand new approach of (or utilizing) Tailwind!

Tags: CascadeCSSLayersTailwindUtilities
Admin

Admin

Next Post
Who made Donkey Kong Bananza? Nintendo lastly spills particulars

Who made Donkey Kong Bananza? Nintendo lastly spills particulars

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Blue Prince’s Sport Breaking PS5 Save Bug Lastly Will get Mounted

Blue Prince’s Sport Breaking PS5 Save Bug Lastly Will get Mounted

May 22, 2025
N Korean Hackers Drop NimDoor macOS Malware Through Faux Zoom Updates

N Korean Hackers Drop NimDoor macOS Malware Through Faux Zoom Updates

July 3, 2025

Trending.

New Win-DDoS Flaws Let Attackers Flip Public Area Controllers into DDoS Botnet through RPC, LDAP

New Win-DDoS Flaws Let Attackers Flip Public Area Controllers into DDoS Botnet through RPC, LDAP

August 11, 2025
Microsoft Launched VibeVoice-1.5B: An Open-Supply Textual content-to-Speech Mannequin that may Synthesize as much as 90 Minutes of Speech with 4 Distinct Audio system

Microsoft Launched VibeVoice-1.5B: An Open-Supply Textual content-to-Speech Mannequin that may Synthesize as much as 90 Minutes of Speech with 4 Distinct Audio system

August 25, 2025
Stealth Syscall Method Permits Hackers to Evade Occasion Tracing and EDR Detection

Stealth Syscall Method Permits Hackers to Evade Occasion Tracing and EDR Detection

June 2, 2025
The place is your N + 1?

Work ethic vs self-discipline | Seth’s Weblog

April 21, 2025
Qilin Ransomware Makes use of TPwSav.sys Driver to Bypass EDR Safety Measures

Qilin Ransomware Makes use of TPwSav.sys Driver to Bypass EDR Safety Measures

July 31, 2025

AimactGrow

Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

Categories

  • AI
  • Coding
  • Cybersecurity
  • Digital marketing
  • Gaming
  • SEO
  • Technology

Recent News

Gears Of Warfare: Reloaded’s First Fixes Are Now Obtainable

Gears Of Warfare: Reloaded’s First Fixes Are Now Obtainable

August 28, 2025
“Be your self” | Seth’s Weblog

For individuals who don’t care that a lot

August 28, 2025
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved