Is the :last-child selector bad for performance?

前端 未结 3 2105
迷失自我
迷失自我 2021-02-09 05:47

I use :last-child selector plenty of times, mostly when using border-bottom in a list where I use border: none; for the last child, or whe

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 06:40

    In general, the core CSS selectors perform well enough that most of us should not be worried about using them. Yes, some of them do perform worse than others, but even the worst performing ones are unlikely to be the main bottleneck in your site.

    Unless you've already optimised everything else to perfection, I would advise not worrying about this. Use a profiling tool like YSlow to find the real performance issues on your site and fix those.

    In any case, even if there is a noticable performance implication for a given CSS selector (or any other browser feature), I would say that it's the browser makers' responsibility to fix it, not yours to work around it.

提交回复
热议问题