TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

My favourite 3 lines of CSS

121 pointsby chensterabout 2 years ago

18 comments

zoulabout 2 years ago
I am increasingly worried about the “smart” CSS solutions. The spec is already huge, the selectors are hard to read and google, the interplay between various features is devilishly complex. And the CSS community seems to be very fond of these smart hacks where people in the know say “Oh, that’s just Foo’s variation on Bar’s flex owl hammer” and you are left to study the CSS lore for hours to decrypt the two or three letters. I just wish we would value simplicity over cleverness.
评论 #34881654 未加载
评论 #34878142 未加载
评论 #34878015 未加载
评论 #34877973 未加载
评论 #34879981 未加载
评论 #34877987 未加载
评论 #34877896 未加载
评论 #34877926 未加载
评论 #34880826 未加载
评论 #34882873 未加载
jraphabout 2 years ago
The lines in question:<p><pre><code> .stack &gt; * + * { margin-block-start: 1.5rem; } </code></pre> I got it immediately because I think I&#x27;ve been doing something similar for a while. I identified the problem it solves. I understand that if you haven&#x27;t encountered the situation, it&#x27;s probably hard to decipher.<p>It reads like: apply a top margin to all direct children that are not the first one.<p>I write it like this:<p><pre><code> .stack &gt; :not(:first-child) { margin-top: 1.5rem; } </code></pre> I probably should start using -block-start. I&#x27;ll keep my selector though I think.<p>I didn&#x27;t know about the default value parameter of --var, I&#x27;ll probably use it too.
评论 #34878424 未加载
评论 #34878224 未加载
评论 #34879002 未加载
评论 #34881079 未加载
woahitsrajabout 2 years ago
We get so much power from just setting global scoped styles like this it&#x27;s so strange to me that more of these patterns aren&#x27;t common or included in minimal css frameworks.<p>With all the recent criticism of tailwind, css-in-js, and other bloated frameworks I truly feel like 90% of projects could get away with a handful of sensible global styles or &quot;classless css&quot; and then aggressive use of components with scoped styles. You hardly ever need anything else
评论 #34877923 未加载
评论 #34878319 未加载
ironmagmaabout 2 years ago
It’s amazing that CSS has such advanced features that can do these things, but at the same time if you actually use them extensively and then I inherit your code, you kind of deserve a knifing.
评论 #34877694 未加载
评论 #34877953 未加载
评论 #34885039 未加载
adityaathalyeabout 2 years ago
Shout out to Andy and Heydon for their book <i>Every Layout</i>. It made CSS sensible to me.<p>By no means am I an expert, but I thoroughly enjoy writing CSS using techniques they teach in the book. Somehow, it helps me to think of CSS as a constraint programming system. Combinators are that --- layout constraint directives.<p>Architecturally, I really like the choice of pulling apart CSS in terms of structural definitions (Stack, Box, Switcher etc.), style definitions (applied to leaf nodes as far as possible), and global rules, ratios, and units (e.g. modular scale).<p>I think the system composes beautifully and lets me do a <i>lot</i> with a very small set of core definitions.<p>My personal site uses those techniques: <a href="https:&#x2F;&#x2F;www.evalapply.org&#x2F;static&#x2F;css&#x2F;style.css" rel="nofollow">https:&#x2F;&#x2F;www.evalapply.org&#x2F;static&#x2F;css&#x2F;style.css</a><p>edit: formatting
grishkaabout 2 years ago
Here are my favorite 4 lines of CSS:<p><pre><code> *, *::before, *::after{ box-sizing: border-box; overflow-wrap: break-word; }</code></pre>
评论 #34878248 未加载
评论 #34878104 未加载
lucas_codesabout 2 years ago
All these comments complaining about complexity of the selectors - if you haven&#x27;t read the MDN page on selectors in the last 5 (10?) years, perhaps now is the time?<p>We were begging for these features for years and it was a nightmare waiting for enough browser support.
personjerryabout 2 years ago
While this is clever, it&#x27;s rather difficult to understand and maintain. Imagine having to sift through a CSS file full of &gt; * + * and assorted symbols and figuring out what they mean (and seeing this article, it&#x27;s clearly not that simple to explain in documentation either).
评论 #34878158 未加载
评论 #34881586 未加载
asplakeabout 2 years ago
In case you had to look it up (I did), the lobotomised owl: <a href="https:&#x2F;&#x2F;alistapart.com&#x2F;article&#x2F;axiomatic-css-and-lobotomized-owls&#x2F;" rel="nofollow">https:&#x2F;&#x2F;alistapart.com&#x2F;article&#x2F;axiomatic-css-and-lobotomized...</a>
shashanoidabout 2 years ago
Mine&#x27;s display: flex, flex-direction: row, justify-content: space-between
评论 #34878722 未加载
评论 #34877796 未加载
评论 #34877817 未加载
评论 #34877904 未加载
评论 #34877942 未加载
just-tomabout 2 years ago
I think that this sort of CSS is smart being put in some kind of reset.css, being a base for the design, rather than being used occasionally while developing. In both cases, it would be smart to have explicit comments describing what the snippets do.
microflashabout 2 years ago
Very nice. I like the elegance of owl selectors, particularly when describing the spacing relationships between adjacent siblings.<p>It helps avoid bleeding issues of space which used to require :last-child &#x2F; :first-child &#x2F; :only-child overrides.
firstfewshellsabout 2 years ago
This is basically a frontend person looking for some validation that they are so smart.
dickjoabout 2 years ago
Respectfully, I&#x27;m finding the value of this blog post extremely difficult to understand. The author&#x27;s arguments against gap just don&#x27;t make sense and I question the logic of their entire design philosophy - the author dismisses gap and says &#x27;The parent is in complete control and the child elements have no say in what gap is at any given moment.&quot;<p>...but that&#x27;s exactly how a sound design system SHOULD work. Structural components (containers etc) SHOULD be in complete control of child distribution. I simply cannot imagine what a nightmare having to manage margin at an atomic component level for everything would be instead of just spelling out a few container components for them all to live in.<p>Furthermore the resistance to using the two display types that utilise the gap property (flex + grid) is absolutely bizarre. No sane person would avoid these tools as web dev without them is messy and utterly maddening, so this resistance makes no sense at all.
评论 #34878819 未加载
atoavabout 2 years ago
As someone who decidedly likes CSS I think something like this is &quot;too clever&quot;. There are some things that should be as boring as possible. Layouts themselves are already a complex matter, so even the most boring and readable css will not be totally boring.<p>When I was younger I also had a phase where I liked to do things like these because I could. Nowadays I do things in a way that doesn&#x27;t waste my own (or other people&#x27;s) time by being too clever
ge96about 2 years ago
For me it would be:<p>border box, flex, the trick to make a square with ::before and content&#x2F;padding 100%
评论 #34879104 未加载
mariusmgabout 2 years ago
.prose :is(h2 + <i>, h3 + </i>, h4 + *)<p>A person which values their sanity would not write this in CSS.
p2hariabout 2 years ago
oh,I was expecting this.<p>@tailwind base;<p>@tailwind components;<p>@tailwind utilities; :)