(Note: I'm avoiding :is() for the sake of showing off how CSS can be nested - however, using + :is(h1, .h1, h2, .h2, ...) like in your comment would also work.)
There is also the :heading selector that would help here, but unfortunately it's not supported by any browsers yet, as it's still considered experimental.
Nice!! I didn’t even think about nesting. Also I don’t think you even need the first & so technically I think the selector inside the curly braces could just be +&
I think maybe slightly shorter would be to use the :is() selector for the first too, and then exclude (or revert) the change with h2 + :is(.h1, h1) {} etc...
I'm no web developer, but from what I gather, no matter how the <h1>,<h2>,<h3>,<h4>,<h5>,<h6>, elements and elements of class ".h1",".h2",".h3",".h4",".h5",".h6" are ordered relative to each other, they'd all get margin-top:-200px.
I'm guessing cases like:
<h1> Qui dolorem ipsum </h1>
<div> Quia dolor sit amet </div>
You can add in CSS, but that's not what the + symbol is doing here. That's the sibling selector. h1 + h2 will match an <h2> element that comes right after an <h1> element, such as:
<h1>Title</h1>
<h2>Subtitle</h2>
<div>Text</div>
Math (including addition) can be done within values using calc, such as:
68
u/TheJackuB Jan 30 '26
I wonder if there is a shorter version than this, without preprocessor:
100
u/Emotional-Bake5614 Jan 30 '26 •
the file should be named burj-khalifa.css
14
u/Aphrontic_Alchemist Jan 30 '26 edited Feb 01 '26
I'm no web developer, but from what I gather, no matter how the <h1>,<h2>,<h3>,<h4>,<h5>,<h6>, elements and elements of class ".h1",".h2",".h3",".h4",".h5",".h6" are ordered relative to each other, they'd all get margin-top:-200px.
I'm guessing cases like:
prevents something like
My naïve fix is putting a class like this:
into the required elements, e.g.
42
u/dz2048 Jan 30 '26
Negative top margin is it's own horror
7
u/robinw77 Jan 30 '26
Wow I was not expecting the full horror of what I saw when I tapped on the image to expand it
6
u/cayenne0000 Jan 30 '26
Scarf design from hell
4
u/mkluczka Jan 30 '26
You're a CSSSSS developer Harry
2
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jan 30 '26
I am so far behind on this shit. I didn't even know you could add stuff in CSS. Or whatever + does.
2
u/DefinitionPhysical46 Feb 02 '26
Ah the H+1 problem!!!
1
u/minecrafttee Jan 30 '26
Why??
1
u/Ronin-s_Spirit Feb 03 '26
Having a separate class for a specific "heading" is crazy, but at least they coulda used
:is()...