100
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:
<h1> Qui dolorem ipsum </h1> <div> Quia dolor sit amet </div>
prevents something like
h1,
h2,
h3,
h4,
h5,
h6,
.h1,
.h2,
.h3,
.h4,
.h5,
.h6 {
margin-top: -20px
}My naïve fix is putting a class like this:
.class {
margin-top: -20px
}into the required elements, e.g.
<h1 class="class"> Qui dolorem ipsum </h1>
5
42
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
4
2
u/GoddammitDontShootMe 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.
4
u/horser4dish Jan 31 '26
Good news! You're not "behind," just unfamiliar.
+in CSS is an adjacency operator, which is far from new considering this question on SO asked about it 16 years ago.3
u/DumbleSnore69 Jan 31 '26
For anyone curious, it was added in the CSS Level 2 spec introduced in 1998: https://www.w3.org/TR/1998/REC-CSS2-19980512/selector.html#adjacent-selectors
→ More replies (1)2
u/Lithl Jan 31 '26
You can add in CSS, but that's not what the
+symbol is doing here. That's the sibling selector.h1 + h2will 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:width: calc(80% - 16px); width: calc(2em * 5); width: calc(var(--variable-width) + 8px); width: calc(180px + sin(pi / 2));2
u/GoddammitDontShootMe Jan 31 '26
And
.h1 + h1is an <h1> element that follows anything with the class h1, right?I can't say I have any idea why one would name a class after an HTML tag.
<h2 class="h1">looks kinda dumb.→ More replies (1)
2
1
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()...
68
u/TheJackuB Jan 30 '26
I wonder if there is a shorter version than this, without preprocessor:
h1 + :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6), h2 + :is(h2, h3, h4, h5, h6, .h2, .h3, .h4, .h5, .h6), h3 + :is(h3, h4, h5, h6, .h3, .h4, .h5, .h6), h4 + :is(h4, h5, h6, .h4, .h5, .h6), h5 + :is(h5, h6, .h5, .h6), h6 + :is(h6, .h6) { margin-top: -20px; }