Defining CSS media queries within selectors

前端 未结 3 1653
我在风中等你
我在风中等你 2021-02-01 16:48

Are there any issues (performance is my primary concern) if instead of defining css selectors within media queries (example 1), you define media queries within css selectors (ex

3条回答
  •  离开以前
    2021-02-01 17:33

    There shouldn't be a performance difference looking at the way browsers handle media queries. Browser engines do serialize and strip out duplicated media-queries so they only need to evaluate each media query once. Also they cache the queries so that they can re-use it later on. It doesn’t matter if you use one big or multiple media-queries in your code assuming your values are mostly the same.


    Some of the possibilities when there can be performance issues

    • You use multiple media queries with different values and the browser window is re-sized. As the browser window is re-sized, multiple media queries can be a big overhead on the cpu.
    • When the CSS selectors are too complex. A complex CSS selector is much performance hindering than multiple media queries. So having multiple media queries inside complex selectors can cause performance issues

提交回复
热议问题