12
0and1
6y

Usually my workplace is pretty chill, but today something rantworthy happened!

During code review, I found this guy had styled each element inside his components using nth-child selectors. For instance, in a card the heading was styled by nth-child(1), the text was styled by nth-child(2) and so on... No use of actual fucking classnames.

When I pointed this out, he told me it was actually the better way of doing things because classnames increase the size of the HTML document!

He also claimed proudly that nth-child() is more efficient in performance (idk - anybody can confirm this?)

I'm the only "css guy" there so nobody could second my views. Posting it here so that I can show this to him tomorrow by demonstrating what opinion other css devs have on this and prove my concerns / convince him to change his code.

Comments
  • 1
    Oh my :D
  • 1
    It's common practice in css GRID Layout tho.
  • 6
    @heyheni yeah well it was nothing grid related. It's like you style a simple card component but do the css without class names.

    I mean what if someone has to change something layout. Then the design is wrecked at once, as everything is selected using its index in the dom.
  • 9
    Separation of concerns: any change in markup will break his styles. Adding a new link/div will require changing all of that markup's associated css. There's a reason they're separate.

    As for "efficiency"... what's the goal here? To have your page rendered a few ms faster? Minifying your css has more of an effect due to reduced download times. Or replacing that png with a jpg.

    Also: what an unmaintainable mess. I'd have him take a css/design course. If that didn't teach him better practices, he wouldn't get to do design projects again.
  • 1
    @Root ikr! Thank you!!
  • 5
    @0and1 there is one additional point I guess...

    With nth-child you have no fucking clue what the shit should be doing....

    div > p:nth-child(1)

    vs

    .p-headline

    And really. I don't wanna think about large pages, eg. search formulars, without descriptive naming....

    It reminds me of using goto with Line numbers.

    Pot hitting in a mine field....
  • 4
    That's total BS. The actual use case for such an iterator is repeating patterns, like alternating table row background colours so that the table is easier to read. But not to make spaghetti markup.
Add Comment