No mourning the bad old days of CSS
I remember, a very long time ago, I interviewed for a job at the All Music Guide, which was based in Ann Arbor. It was a FED position, and when asked about CSS I was very confident in my ability to completely reshape the world through CSS alone. The CSS Zen Garden was a big thing at the time, and I had semi-recently abandoned tables for page layout, primarily just by reading O'Reilly's CSS reference book by Eric Meyer. Long story short, the interviewer literally laughed at me. Presumably it was partially my youthful hubris, but he commented that "You haven't seen this code." Now... I don't know if I was right or if he was. When I didn't get the job, it's not like I went and tried to do it on my own to prove I could. I was searching for a job. But I do know that these days, you almost certainly could do it.
This is a long prelude to me using the :has pseudo-class for the first time. It's been fully supported by browsers for only a couple years, which is an eternity in most tech time but considering there hasn't been a new CSS spec in quite some time, it's fairly recent. Basically it allows you to pull a switcheroo on any other selector. For instance, if I had a definition list:
<dl>
<dt>Def Title</dt>
<dd>Item</dd>
<dd>Item</dd>
<dt>Def Title 2</dt>
<dd>Item</dd>
<dd>Yet another item</dd>
</dl>I could target the second <dt> by using the adjacent selector:
dd + dt { ... } But with :has, I could flip it around to target the last dd that I used to find it:
dd:has(+ dt) { ... }And that's very practical! That's a simple example, though it is the one that I needed this for, but it opens up so many different possibilities of targeting when you are unwilling or (more to the point) unable to add a class to something.
Been a while since I nerded out on something CSS-related. But the days of laughing at a kid who thinks he can target any element via CSS are very much over, and like the browser wars, I will not mourn them.
