Is there such a thing as min-font-size and max-font-size?

前端 未结 11 590
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 22:13

I\'m trying to make a font in a div responsive to the browser window. So far, it has worked perfectly, but the parent div has a max-width of 525px. Res

11条回答
  •  暖寄归人
    2021-01-29 22:40

    Rucksack is brilliant, but you don't necessarily have to resort to build tools like Gulp or Grunt etc.

    I made a demo using CSS Custom Properties (CSS Variables) to easily control the min and max font sizes.

    Like so:

    * {
      /* 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);
    }
    

提交回复
热议问题