CSS Selectors: A Visual Guide
fffuel.co
fffuel.co
@namespace "bogus"; /* unnamed */
@namespace aitchtee "http://www.w3.org/1999/xhtml";
@namespace esvee "http://www.w3.org/2000/svg";
* { /* will not match anything, because "bogus" NS */ }
html { /* also nothing, because "bogus" NS */ }
*|* { /* will match everything */ }
aitchtee|title { /* will not match SVG title element, only the HTML one */ }
aitchtee|*:root { /* will match html */ }
esvee|* { /* all SVG elements */ }New in CSS Selectors Level 4 is the ability to optionally pass a selector list into :nth-child() and :nth-last-child().
For example, :nth-child(2 of .highlight) selects the second matching element that has the .highlight class. Put differently: out of all children with the class .highlight, select the second one.
More here: https://github.com/00000o1/selector-generalization
There've been multiple attempts at such a thing over the years, but I like this approach for its essentially simple foundation in solid algorithms.
Be warned tho this code is old! I haven't yet got around to updating it to make it more "modern" etc!!
[title^=“old”]
and
[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:"] ^ means match input start
$ means match input end
Makes remembering the CSS selector syntax easier once you know that. (Or makes the regex syntax easier to remember?)To the point, the :not(:first-child) option should similarly be able to minimize the total number of rules.
Strict equivalent of
* + *
would be :where(:not(:first-child))Minor typo nit: the ::placeholder bold selector name has been copy-pasted in the sections for ::selection and ::marker.
I checked on both FF and FF Focus on iOS and got regular scrolling behavior.
Scrolling seems fine. Firefox on Pixel3
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.
Which is often a warning sign of a bad design. The times I've dealt with systems that bury a certain piece of text in either a content file or a template or the database...
> It’s less work by far to ensure you can find all of the CSS though.
Hmm... depends. I've seen things like React embedding the CSS directly in with the markup and component logic etc. So this hasn't necessarily gotten any better — in fact, a site consisting JUST of html files would probably be easier to find CSS in even if it's all added via inline style attributes.
Zealots provide solutions that cannot possibly survive contact with actual humans. The rest of the team talks about them behind their backs.
> I've seen things like React embedding the CSS directly in with the markup and component logic etc.
You were talking about bad designs? Embedded styling is not Cascading Style Sheets. It’s embedded styling. There’s no sheet, and no cascade.
Nothing is free, and few things are easy. There are lines that are easier to maintain in practice than others, and separation of CSS is one of the former.
I think that's needless pedantry; the contents of the `style` attribute still needs to be valid CSS.
We had in-line style before we had CSS. We are going back and nobody remembers why we’ve had CSS for twenty years? Read some history.
Edit: actually, even when I was working with CSS in 2003 (IIRC, we absolutely were using separate CSS files then), this attitude would have been unhelpful, to say the least.
I know because every place I've worked in the last few years uses some form of CSS in JS.
Calling it a feature that you have CSS in your JS is tantamount to saying you’re writing legacy code. Which happens, but don’t be cheerful about it.