Tailwind CSS: From Side-Project Byproduct to Multi-Million Dollar Business
adamwathan.me308 pointsby adamwathan109 comments
.foo .bar {
.baz & {
color: red;
}
}
In Sass, that would compile to: .baz .foo .bar {
color: red;
}
With native nesting, it effectively compiles to: .baz :is(.foo .bar) {
color: red;
}
The Sass version matches this DOM structure: <div class="baz">
<div class="foo">
<div class="bar">
...
But the native version matches all of these structures: <div class="baz">
<div class="foo">
<div class="bar">
...
<div class="foo">
<div class="baz">
<div class="bar">
...
<div class="foo baz">
<div class="bar">
...
Not a criticism at all (the `:is(...)` behavior is a very useful and welcome enhancement to CSS) but a notable difference worth understanding coming from Sass. .btn { display: inline-flex; justify-content: center; padding: 8px 16px; border: 1px solid transparent; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); font-size: 14px; border-radius: 6px; color: #fff; background-color: rgb(79 70 229) } .btn:hover { background-color: rgb(67 56 202); outline: 2px dotted transparent; outline-offset: 2px; box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgb(99 102 241), 0 1px 2px 0 rgb(0 0 0 / 0.05) }
<button class="
inline-flex justify-center
py-2 px-4
border border-transparent rounded-md
shadow-sm
text-white text-sm font-medium
bg-indigo-600 hover:bg-indigo-700
focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500
">
Submit
</button>
My experience (and the experience of thousands of others) is that in practice, an approach like Tailwind is much more maintainable, even if it's superficially ugly. .btn {
display: inline-flex;
justify-content: center;
padding: 8px 16px;
border: 1px solid transparent;
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
font-size: 14px;
border-radius: 6px;
color: #fff;
background-color: rgb(79 70 229);
}
.btn:hover {
background-color: rgb(67 56 202);
outline: 2px dotted transparent;
outline-offset: 2px;
box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgb(99 102 241), 0 1px 2px 0 rgb(0 0 0 / 0.05);
}
...as opposed to what everyone has done historically, which is pick some arbitrary huge value like:
No real practical benefit, just satisfyingly more "correct".