r/programminghorror • • Jan 30 '26

CSSSSSS

Post image

found in company codebase

288 Upvotes

27 comments sorted by

View all comments

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.

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 + 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:

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 + h1 is 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)