Problem
- When projects with many UI developers, start to code components in their own way, each declaring their own custom css classes, as per need.
Traditional way
When we consider a simple well know issue to center a "div" in a page, this is how we typically create a class, with all the necessary styling.
<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 */ }
- Since all these classes are available in the global scope, any developer can use them freely.
Pros
- Reduces CSS Bundle size significantly.
- Ensures component styling to be consistent across the team.
- Developers can rapidly prototype their ideas, with less effort on redoing the same style.
Cons
- Learning curve, each developer needs to get familiar with classes that already existing.
- Project needs to keep proper documentation, when adding these Global declared classes for others to consume.
Vue JS Pitfalls
:deep() / ::v-deep
- the bain ? of Vue JS css targeting.
Traditional Classes
- Targeting and Applying styling for the classes is very easy
div { ::v-deep .center-div { background-color: red; } }
Taiwind Classes
- Developers need to get very creative when targeting "div"
div { ::v-deep :first-of-type { background-color: red; } }
How to Introduce Tailwind CSS Classes into your Application
Traditional way
- we can easily install them with
Tailwind Installation
npm install -D tailwindcss npx tailwindcss init
- but this will install (i.e register) a plethorah of all the classes, in the global scope.
Unconventional ? way
when your Application already has an existing css library, it would be ideal to cherry pick, the classes we need and add them in one css file and register it globally in the App.
Say your Application only wants flexibility in flexbox styling
-- Get a list of the classes you need from flex stylescherry pick the classes you ? assume ? your application needs, and add them as per need.
with this way we can keep the CSS bundle significanlty small, but the development team needs to have tight control over css they apply ?.
/* 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; }
Conslusion
- Using Atomic classes with Tailwind as reference can
- Reduce a Project's CSS footprint.
- Maintain Styling consistensy across the Application.
- Increases Developer speed, with rapid prototyping. ?
The above is the detailed content of Why add Tailwind CSS Atomic Classes to project ❓. For more information, please follow other related articles on the PHP Chinese website!

There's been a run of tools, articles, and resources about color lately. Please allow me to close a few tabs by rounding them up here for your enjoyment.

Robin has covered this before, but I've heard some confusion about it in the past few weeks and saw another person take a stab at explaining it, and I wanted

I absolutely love the design of the Sandwich site. Among many beautiful features are these headlines with rainbow underlines that move as you scroll. It's not

Many popular resume designs are making the most of the available page space by laying sections out in a grid shape. Let’s use CSS Grid to create a layout that

Page reloads are a thing. Sometimes we refresh a page when we think it’s unresponsive, or believe that new content is available. Sometimes we’re just mad at

There is very little guidance on how to organize front-end applications in the world of React. (Just move files around until it “feels right,” lol). The truth

Most of the time you don’t really care about whether a user is actively engaged or temporarily inactive on your application. Inactive, meaning, perhaps they

Wufoo has always been great with integrations. They have integrations with specific apps, like Campaign Monitor, Mailchimp, and Typekit, but they also


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.