Is CSS faster when you are specific?

后端 未结 3 702
一生所求
一生所求 2020-12-13 23:49

Is div.container faster than .container ? You know like in jquery if you be more specific with your selectors it is faster since it iterat

3条回答
  •  时光取名叫无心
    2020-12-14 00:21

    Generally, the fewer the rules the better, so .container would be faster than div.container. Apart from caching, the .container gets read first, then other elements have to have the div added on as a second-level filter... unnecessary in many circumstances.

    This is pretty common across engine, though there are some minor deltas.

    See this article: Writing efficient CSS, which although it is from MDN (and is therefore Mozilla-geared) holds true for most of what I know about the engines in general.

提交回复
热议问题