css - using rems with a pixel fallback -


I am working on the mobile framework. This project has a wide range of requirements for which browsers and The equipment can be completed with a large scale. One of my important places for the goal is India, where U.K. Or the usage of browsers and devices in the US is quite different.

India's browser usage

UK browser usage

Browsers, which I need to target for territory of India, Opera, Android, UK Browser and Nokia , But each of them has a little quarrel Opera mini-rim does not support Android (before chrome) v2-v4 has problems with both rim and ems

- I'm right Assuming that the latest version of Android Skrn chrome and are pre-installed with the OS web browser?

I would like to use reams, because it inherits the M-Scale of the nested material to its original element. Although based on research, I need to return a fall.

So I'll need to declare a px value. For example, can I do this:

  h1 {font-size: 24px; Line-height: 30px; Margin-down: 10px; Font size: 1.846rem; Line-height: 2.308rem; Margin-down: 0.769rem} / * 24px / 30px / 10px * /  

Or do I have to do something like this?

  h1 {font-size: 24px; Line-height: 30px; Margin-down: 10px} h1 {font-size: 1.846rem; Line-height: 2.308rem; Margin-down: 0.769rem} / * 24px / 30px / 10px * /  

Or is anything better?

I have some JS polyfil, such as, but in cases where JavaScript is not enabled, this will not work.

In addition to this, I try to focus on the performance, so I want to keep the number of requests a minimum and keep CSS as clear as possible.

Thank you

The announcement of both styles will work well. CSS renders the code in a huge fashion, it means that one price has been announced after the second, the latter will be used. If a browser can render px but can not render rim , then the rim value will only be ignored. If a browser can present both px and rim / code>, both will be used:

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

In this example, rim is used on browsers supporting that unit , And px will be used on those who are not.

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

In this example, px will be used on both browsers which will be < Code>

You will better review which browsers support this unit.


For display, each CSS contains a CSS file equal to 1 byte, more bytes contained in your stylesheet, will now take a browser to download it. Of course, adding the rem value with the px value will eventually add to the download time, but most of the time it is negligible.


For the Android devices that are bundled with Chrome: No, this is not the case. It is completely dependent on the manufacturer.


Comments