em vs px… for mobile browsers

前端 未结 5 2092
醉酒成梦
醉酒成梦 2021-02-01 20:26

For desktop browser all modern browser uses Zoom functionality so we can use PX but if same site can be seen on mobile then would px not be good for zooming in mobile browsers.

5条回答
  •  不知归路
    2021-02-01 20:27

    You can use this trick for converting fonts from px to em in your CSS:

    body {
      font-size: 62.5%; /* resets the page font size */
    }
    

    Then specify your font sizes like this:

    p {
      font-size: 0.8em; /* equals 8px */
      font-size: 1.0em; /* equals 10px */
      font-size: 1.6em; /* equals 16px */
      font-size: 2.0em; /* equals 20px */
    }
    

    And so on. Then you can convert px to em for your layout at PXtoEm.com.

提交回复
热议问题