CSS fonts rem trick: 62.5% or 6.25%

后端 未结 3 1526
忘掉有多难
忘掉有多难 2021-01-13 13:31

I would like to use font sizing with REM and on internet I found following trick:

html { font-size: 62.5%; } 
body { font-size: 1.4rem; } /* =14px */
h1   {          


        
3条回答
  •  礼貌的吻别
    2021-01-13 14:12

    You could use 6.25% so that you get your nice 1:1 rem values, then set font-size: 16em; on body to get the best of both worlds. It'll fix the tiny font problem in old browsers, and browsers that do understand your rem declarations will ignore it by looking to html's font-size when calculating sizes. As far as I can tell there are no drawbacks to doing it this way and you actually get a better sized fallback than you do with 62.5%, but there may be something I've missed so use it with caution.

提交回复
热议问题