41 points · by speckx · 2y ago · 56 comments
Sigh. We managed to raise a generation for which an instant interaction on a 1000+MHz multi-core gpu-accelerated 1000+MB/s io system feels snappy and that’s special. Good job, goob job.
you could add a negative margin to offset the border, or an always-on transparent border that only changes colour when you hover – but those can interfere with other CSS rules
The worst part of CSS is its globalness. You can’t have two paddings sourced from different subsystems, can’t name a border so you could address it specifically (e.g. as in el:border(myhover) {background: <gradient>}). CSS is so poor and antipattern and nobody bats an eye. You write an article like this and already see all these fragile hacks advices coming in, normalized by years of stockholming through even most basic layouts.
For some "web developers", this is literally how they create a page:
import React from 'react';
function App() {
return (
<div>
<h1>Hello world!</h1>
<p>This is my HTML page.</p>
</div>
);
}
export default App;Added: And it was not a deliberate choice but kind of a necessity.
Anyway, your comment feels like a straw man; I don't know anyone who actually believes what you're claiming, nor is this sentiment anywhere on HN. The closest things are discussions about whether your website should work with JS disabled whenever a too-clever website is linked.
Nah they're right. There's developers, in major corporations right now, who literally have no idea that you can just put HTML in a container and who are so drunk on node.js that they LITERALLY DO NOT UNDERSTAND what something like nginx, traefik, or Caddy is for.
These people are building healthcare systems.
For some "systems developers" this is literally how they create a program:
#include <stdio.h>
int main(int argc, char *argv[]) {
println("Hello world.");
}
GTK/Unity/WinForms, everyone has their working level of abstraction.But global-ness is what you want from design directives. You want all your buttons to look the same, your links consistent. You want to define your base fonts once and then not have to worry about it for the rest of the build. You want to have your vertical rhythm (line spacing) repeated on most pages. You want most pages to have the same background and foreground colours. CSS syntax gives you all that for free.
Giving multiple elements the same border definitions is easy:
elem,
another-elem,
.some-class,
#just-this-one {
border: whatever;
background: swoosh;
}
When I look at the hoops you have to leap through to get the same behaviour using any of the frameworks, my mind reels. Build steps, runtime libraries, repeated syntaxes in the mark-up...I accept that managing things like the shared border example can get fiddly. SASS made it easier; some flavour of react-plus-css-helper-library thing can make it easier, kinda, if you squint. But it's actually _very_ simple to write the basic core idea in plain CSS. Personally, I feel that the discipline required to manage larger CSS codebases isn't that different than the discipline required to write good JS or TS; we just have a habit of pretending we shouldn't need to do that and wishing someone else would (via a library, or changing the standards). I don't know why we're happy doing it in JS or TS, but not CSS.
fooModule.*(x),
bar(x),
Math.floor(x) {
if (x === 42) return “oops”;
return thisfunc(x);
}
Or as COMEFROM. The proper way for modularity is to import subtrees of declarations and have them applied explicitly. // elem.css
elem {
use border-bg from “./bbg.css”;
}
// html
<div>
import elem from “./elem.css”
<elem/> // has it
</div>
<elem/> // doesn’t
I don’t want aspect-oriented/comefrom globalness. It is an antipattern and dead tech in which you have to runtime-debug an element to learn its properties in each case, cause there’s no single place to treewalk your logic from.I was arguing that global declarations are useful. Your example is intentionally differentiatiating similar elements, and placing the specialisation inline with the DOM declaration.
So far these seem more like style preferences. I can’t infer the “anti-patterns” you’re concerned about, nor how your version solves them. Could you expand some?
Personally, I much prefer keeping the layout and style code out of my JS/behavior code. It makes both easier to read.
> Outline is a line outside of the element's border. Unlike other areas of the box, outlines don't take up space, so they don't affect the layout of the document in any way.
If you s/border/outline in the dev console on the image you get what you want.
For the icons, I don't understand why the author believes that they need to have two copies of the icon inside the SVG. You can style every property of every element using CSS. If your icon is a single path element, it should remain a path element and be styled something like this:
svg.social path { fill: gray; }
svg.social:hover path { fill: #8df; }
Of course it's possible that I'm missing something, but if all you want is changing color on hover, duplicating the item and using a mask is overkill. .icon:not(:hover) {
filter: grayscale(1);
}<svg><path d=“” fill=“currentColor” /></svg>
element { color: hsl(0 0% 0%) }
One advantage is that you can target the parent element and the SVG will change automatically.
You can also create multiple “shades” by having currentColor on multiple paths with different opacity.
Which, to be fair, is a pretty high cost. The consistency of the greys that only differentiate on hover is half the aesthetic value of the effect.
outline: solid 10px red;
Nearly identical to border, but without affecting layout at all.> ..., or an always-on transparent border that only changes colour when you hover – but those can interfere with other CSS rules
Next week: How to run your Docker React Node Babel Webpack Svelte grocery list application at the EDGE using Kubernetes on AWS serverless EC2 instances with Cloudflare workers.
EDIT: I forgot we're gonna use Bootstrap too.
<button class="bg-blue-600 px-4 py-3 text-center text-sm font-semibold inline-block text-white cursor-pointer uppercase transition duration-200 ease-in-out rounded-md hover:bg-blue-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2 active:scale-95">Hello world!</button>
It works in TFA.
img{border: 10px solid transparent;transition:border 0.3s}
a:hover img{border: 10px solid red;}