Responsive font size in CSS

前端 未结 30 2755
刺人心
刺人心 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 07:54

    If you are using a build tool then try Rucksack.

    Otherwise, you can use CSS variables (custom properties) to easily control the minimum and maximum font sizes like so (demo):

    * {
      /* Calculation */
      --diff: calc(var(--max-size) - var(--min-size));
      --responsive: calc((var(--min-size) * 1px) + var(--diff) * ((100vw - 420px) / (1200 - 420))); /* Ranges from 421px to 1199px */
    }
    
    h1 {
      --max-size: 50;
      --min-size: 25;
      font-size: var(--responsive);
    }
    
    h2 {
      --max-size: 40;
      --min-size: 20;
      font-size: var(--responsive);
    }
    

提交回复
热议问题