So they essentially reinvented the style attribute in a less verbose form?
So they essentially reinvented the style attribute in a less verbose form?
I've used CSS, and Tailwind and not worrying about naming everything correctly and not skipping around different files is a dream for me. Perhaps that's my brain, Idk.
Further I have gone over old code, and haven't had any problem with maintainability
It's not actually the same thing. What you're talking about is inline styling which takes precedence over class-based styling. It's generally considered bad practice to rely on inline styles. The traditional approach is `style="card"` not `style="...a bunch of rules..."`
<div class="block text-black">...</div>
<div style="display: block; color: black;">...</div>
Looks like the same thing to me. Only shorter.<style> .someClass { display: block; color: black; } </style>
<div class="someClass">...</div>
If it's a reinvention it's objectively better at least.
```css
.card {
...
}
```
```html
<div class="card" />
```
RATHER than a reinvention of ```html
<div style="..." />
``` <div class="block">...</div>
<div style="display: block;">...</div>
https://tailwindcss.com/docs/displaySo we've gone from inline styling to separating markup and presentation with CSS but now we've gone back to inline styling.
Because the presentation affects markup. You'll have to add wrapping divs to accomplish any kind of complex layout for example.
Once you can't separate it in your mental space, it doesn't matter that its in two different files.
> You'll have to add wrapping divs to accomplish any kind of complex layout for example.
I don't know about that. I think selectors are pretty powerful. Have managed to avoid littering the HTML with structural nodes by using them creatively. CSS has gained a huge number of features since I first learned it, there's even better ways to do stuff now.
You can do this with CSS variables now I suppose, but this very quickly becomes "CSS classes, but with extra steps".
I agree, but that place is normally the code/templating engine that generates your webpage. So it really shouldn't matter if it's repeated on the wire.
> You can do this with CSS variables now I suppose, but this very quickly becomes "CSS classes, but with extra steps".
Variables are much simpler and easier to understand than selectors.
I see, we finally reached the root of the issue.
Why are CSS selectors a mistake? Doesn't seem that way to me. Why shouldn't I use them?
Isn't this a symptom of the selectors not being specific enough?
> You can't reliably reuse your styling or components between pages, because the exact same element placed in two different pages might end up with radically different styling
Can you give concrete examples of this happening?
I can provide an example I think is a good use case for highly specific selectors: turning HTML lists into file system trees.
https://www.matheusmoreira.com/css/tree.css
ul.tree,
ul.tree ul {
list-style-type: none;
padding: 0;
}
ul.tree li {
margin-left: 1em;
border-left: 2px solid var(--tree-color);
}
ul.tree li code {
display: block;
position: relative;
padding-left: 1em;
padding-bottom: 0;
line-height: 1em;
}
ul.tree li:not(ul.tree > li:first-child) code::before {
content: "";
position: absolute;
left: -2px;
width: 0.75em;
height: 0.5em;
border: 2px solid var(--tree-color);
border-top: 0 none transparent;
border-right: 0 none transparent;
}
ul.tree li:last-child {
border-left: 2px solid transparent;
}
ul.tree li:has(ul) > code::after {
content: "/";
}
<ul class="tree">
<li><code>~/.files</code>
<ul>
<li><code>~</code>
<ul>
<li><code>.bash_profile</code></li>
<li><code>.bashrc</code></li>
<li><code>.vimrc</code></li>
<li><code>...</code></li>
</ul>
</li>
<li><code>GNUmakefile</code></li>
</ul>
</li>
</ul>
That sort of thing feels like a perfect fit for CSS selectors to me. I admit it's not a super complex design (or even a beautiful one, I suck at design) but it does demonstrate the value of selectors.Well, yeah, but that's a "you're holding it wrong" argument. If you make your selectors specific enough then they will apply to the right elements, and if they applied to the wrong elements, well, they weren't specific enough. In practice people resort to only ever using a classname as a selector because anything else is too likely to break; there's no way to find out which selectors apply to which elements or which elements are covered by which selectors (e.g. you can't do the equivalent of "find references" on a variable).
> Can you give concrete examples of this happening?
Only on the level of, like, "my company's whole webapp" (but I've seen it cause real bugs in prod if that's what you're getting at). Getting surprised by which selectors get applied isn't a problem you can show in small examples, because it doesn't happen with small examples; it's only when the selectors and DOMs are too complex to keep in your head that you have a problem.
> That sort of thing feels like a perfect fit for CSS selectors to me.
Why does it need selectors though? It doesn't change based things at higher level (which is the failed ideology that the likes of the CSS Zen Garden were pushing - the idea that you want your component's styling to magically change to fit in with the page it's on or what's happening around it). What are you doing here that you couldn't do with a self-contained component that knew how to style itself?