Responsive font size in CSS

前端 未结 30 3243
刺人心
刺人心 2020-11-22 07:23

I\'ve created a site using the Zurb Foundation 3 grid. Each page has a large h1:

30条回答
  •  梦谈多话
    2020-11-22 08:11

    I saw a great article from CSS-Tricks. It works just fine:

    body {
        font-size: calc([minimum size] + ([maximum size] - [minimum size]) * ((100vw -
        [minimum viewport width]) / ([maximum viewport width] - [minimum viewport width])));
    }
    

    For example:

    body {
        font-size: calc(14px + (26 - 14) * ((100vw - 300px) / (1600 - 300)));
    }
    

    We can apply the same equation to the line-height property to make it change with the browser as well.

    body {
        font-size: calc(14px + (26 - 14) * ((100vw - 300px) / (1600 - 300)));
        line-height: calc(1.3em + (1.5 - 1.2) * ((100vw - 300px)/(1600 - 300)));
    }
    

提交回复
热议问题