suchen
HeimWeb-FrontendCSS-TutorialWenn wir die Rahmenbedingungen der Utility-Klasse kritisieren werden, seien Sie fair darüber

If we're gonna criticize utility-class frameworks, let's be fair about it

I’m not here to raise a shield protecting CSS utility frameworks. I don’t even particularly like the approach, myself, and nothing is above fair criticism. But fair is a key word there. I can’t tell you how many times I’ve seen utility styles compared to inline styles. Sarah Dayan is weary of it:

[…] despite numerous attempts at debunking common fallacies, utility-first enthusiasts keep on having to reply to a staggering amount of misconceptions. And by far,the most tired, overused cliché is that utility classes are just inline styles.

I think this comparison will make it clear:

<div style="color: #3ea8ca;"></div>

<div></div>

The first div has a color set directly in the HTML that is an extremely specific blue color value. The second has a color that is set outside of the HTML, using class name you can use to configure the shade of blue in CSS. Sure, that second one is a fairly limited class name in that, as the name suggests, does one job, but it still offers some abstraction in that the blue color can be changed without changing the markup. It’s the same story with a sizing utility class, say size-xl. That’s also an abstraction we could use to define the padding of an element in CSS using that class name as a selector. But if we were to use style="padding: 10px;" directly on the element in the HTML, that is an absolute that requires changing the value in the markup.

To be fair though (which is what we’re after), there are quite a few classes in utility frameworks that are named in such a way that they are extremely close acting like inline styles. For example, top-0 in Tailwind means top: 0 and there is no configuration or abstraction about it. It’s not like that class will be updated in the CSS with any value other than zero because it’s in the name. “Utility” is a good way to describe that. It is very much like an inline style.

All that configurable-with-smart-defaults stuff puts utility-based frameworks in a different category. Inline styles offer no constraints on how you style things (other than hard limitations, like no pseudo selectors or media queries), while a limited set of utility classes offer quite a lot of styling constraints. Those constraints are often desirable in that they lead to a design that looks consistent and nice instead of inconsistent and sloppy.

To borrow a metaphor I heard in a slightly different context one time: Utility-class frameworks are like bumper bowling for styling. Use the classes and it’ll work out fine. You might not get a strike, but you won’t get a gutter ball either.

Another unfair criticism I hear in conversation about utility frameworks is that you ship way more CSS with them. If you are, then you’re definitely screwing up. In my mind, the main point of this approach is shipping less CSS (only the classes you use). I’m the first to tell you that a build process that accurately and perfectly does this is tricky and could lead to an unhealthy amount of technical debt, but I’ll cede that if you do it right, shipping less CSS is good for performance. Tailwind in particular highly encourages and helps you do this.

So all that said, I think there is all sorts of stuff to criticize about the approach. For example, I personally don’t like looking at all those classes. I just don’t. I’m not an absolutist about perfectly abstract classes, but seeing 10-20 classes on div after div gets in the way of what I’m trying to do when I’m templating HTML. It feels harder to refactor. It feels harder to see what’s going on semantically. It’s harder to parse that list for other classes that I need to do non-styling things. Some of the advantages that I would get from utilities, like scoping styles to exactly where I need them, I often get through other tooling.

I also think utility-frameworks work best in JavaScript component setups where you have Hot Module Reloading. Otherwise, HTML changes tend to trigger entire page refreshes. For example, a tool like Browsersync is pretty darn nice. It does CSS injection when your CSS changes. But it can’t do new-HTML injection; it just refreshes the page. So without Hot Module Reloading, which generally ain’t for your generic HTML site or Static Site Generator, you get worse DX while authoring.

Das obige ist der detaillierte Inhalt vonWenn wir die Rahmenbedingungen der Utility-Klasse kritisieren werden, seien Sie fair darüber. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Wohin sollte 'Podcast' -Link abonnieren?Wohin sollte 'Podcast' -Link abonnieren?Apr 16, 2025 pm 12:04 PM

Für eine Weile war iTunes der große Hund im Podcasting. Wenn Sie also "Abonnieren Sie Podcast" verlinkt haben, um zu mögen:

Browser -MotorvielfaltBrowser -MotorvielfaltApr 16, 2025 pm 12:02 PM

Wir haben die Oper verloren, als sie 2013 Chrome gingen. Gleiches Geschäft mit Edge, als es Anfang dieses Jahres auch Chrome ging. Mike Taylor nannte diese Veränderungen a "abnehmend

UX -Überlegungen zur WebfreigabeUX -Überlegungen zur WebfreigabeApr 16, 2025 am 11:59 AM

Von trashigen Clickbait -Websites bis hin zu den meisten August der Veröffentlichungen sind die Teilen von Schaltflächen seit langem im gesamten Web allgegenwärtig. Und doch ist es wohl diese diese

Wöchentliche Plattformnachrichten: Apple bereitet Webkomponenten, progressives HTML-Rendering, selbsthosting kritische Ressourcen bereitWöchentliche Plattformnachrichten: Apple bereitet Webkomponenten, progressives HTML-Rendering, selbsthosting kritische Ressourcen bereitApr 16, 2025 am 11:55 AM

In der Roundup der Woche geht Apple in Webkomponenten, wie Instagram Insta-Loading-Skripte und einige Lebensmittel für das Denken für selbsthosting kritische Ressourcen sind.

Git pathspecs und wie man sie benutztGit pathspecs und wie man sie benutztApr 16, 2025 am 11:53 AM

Als ich die Dokumentation von Git -Befehlen durchschaut hatte, bemerkte ich, dass viele von ihnen eine Option hatten. Ich dachte anfangs, dass dies nur ein war

Ein Farbwähler für ProduktbilderEin Farbwähler für ProduktbilderApr 16, 2025 am 11:49 AM

Klingt ein bisschen wie ein schweres Problem. Ist es nicht? Wir haben oft keine Produktaufnahmen in Tausenden von Farben, sodass wir das mit dem mit umdrehen können. Wir auch nicht

Ein dunkler Modus wechselt mit React und ThemeProviderEin dunkler Modus wechselt mit React und ThemeProviderApr 16, 2025 am 11:46 AM

Ich mag es, wenn Websites eine dunkle Modusoption haben. Der dunkle Modus erleichtert mir das Lesen von Webseiten und hilft meinen Augen, sich entspannter zu fühlen. Viele Websites, einschließlich

Einige praktisch mit dem HTML-DialogelementEinige praktisch mit dem HTML-DialogelementApr 16, 2025 am 11:33 AM

Ich schaue mir das HTML -Element zum ersten Mal an. Ich habe es für eine Weile dessen bewusst, aber Haven ' Es wurde es noch nicht für einen Dreh genommen. Es hat einige ziemlich cool und

See all articles

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat -Befehle und wie man sie benutzt
1 Monate vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Herunterladen der Mac-Version des Atom-Editors

Herunterladen der Mac-Version des Atom-Editors

Der beliebteste Open-Source-Editor

PHPStorm Mac-Version

PHPStorm Mac-Version

Das neueste (2018.2.1) professionelle, integrierte PHP-Entwicklungstool

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

WebStorm-Mac-Version

WebStorm-Mac-Version

Nützliche JavaScript-Entwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)