Live data from Hacker News

CSS Selectors: A Visual Guide

fffuel.co

11–20 of 59 posts

Re: CSS Selectors: A Visual Guide

#11
post #6

Very cool. It seems to be missing the begins with and ends with selectors for the attr-val. [title^=“old”] and [title$=“old”]

[title^=“old”]

and

[title$=“old”]

Once you get used to using these, and their relatives, you find all kinds of uses for them, like applying styles only to telephone links:

  a[href^="tel:"]

Re: CSS Selectors: A Visual Guide

#14
You can make nth-child repeat by using an arithmetic expression inside the parentheses, like nth-child(3n). They also stack, so you can create pseudorandom transformations to a sequence of elements by adding styles for the first few prime numbers.

Re: CSS Selectors: A Visual Guide

#16
post #13
post #9

Cool but also reminds me why I use inline styles for everything. I don't want to fiddle with selectors. I want to put the styling right on the element.

How do you create reusable styles this way?

modern JS has a bunch of half-assed scenarios for solving this problem that allows you to solve almost everything CSS did a few years ago and helps keep people stuck in ineffective legacy ways of doing it because all their code would have to be rewritten to use straight css.

I know because every place I've worked in the last few years uses some form of CSS in JS.

Re: CSS Selectors: A Visual Guide

#19
post #9

Cool but also reminds me why I use inline styles for everything. I don't want to fiddle with selectors. I want to put the styling right on the element.

In a large app you often can’t easily find all of the html. It’s less work by far to ensure you can find all of the CSS though.

And when the company decides to rebrand and change the color scheme for the whole app, which they will at least half the time, you’ll be glad not to be playing whack-a-mole. Problems that aren’t done when you think they’re done create a lot of friction with the rest of the org. Open ended problems cause engineering to look incompetent. The cost of that problem is immeasurable, and doubly so in a bad economy.

Post reply on HN