using rems with a pixel fallback

前端 未结 2 1662
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-20 00:15

I\'m working on mobile first framework. The project has a broad range of requirements, with a mass of browsers and devices over various locations to cater for. One of my key

2条回答
  •  无人共我
    2021-01-20 00:52

    Both of your style declarations will work fine. CSS renders code in a cascading fashion, this means if one value is declared after another, the latter will be used. If a browser can render px but cannot render rem, the rem values will simply be ignored. If a browser can render both px and rem, the latter of the two will be used:

    h1 {
        font-size: 12px; /* 1. Font size set to 12px */
        font-size: 1rem; /* 2. Font size set to 1rem, overriding previous value */
    }
    

    In this example, rem will be used on browsers which support that unit, and px will be used on those which do not.

    h1 {
        font-size: 1rem; /* 1. Font size set to 1rem */
        font-size: 12px; /* 2. Font size set to 12px, overriding previous value */
    }
    

    In this example, px will be used on both browsers which support rem and browsers which do not.

    Can I Use... will give you a better overview of which browsers support this unit.


    As for performance, each character contained within a CSS file equates to 1 byte. The more bytes contained within your stylesheet, the longer it will take a browser to download it. So of course, adding px values alongside rem values will ultimately add to the download time, but most of the time this is negligible.


    As for whether Android devices come bundled with Chrome: no, this is not the case. This is entirely up to the manufacturer.

提交回复
热议问题