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

前端 未结 11 820
隐瞒了意图╮
隐瞒了意图╮ 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:33

    You can use Sass to control min and max font sizes. Here is a brilliant solution by Eduardo Boucas.

    https://eduardoboucas.com/blog/2015/06/18/viewport-sized-typography-with-minimum-and-maximum-sizes.html

    @mixin responsive-font($responsive, $min, $max: false, $fallback: false) {
      $responsive-unitless: $responsive / ($responsive - $responsive + 1);
      $dimension: if(unit($responsive) == 'vh', 'height', 'width');
      $min-breakpoint: $min / $responsive-unitless * 100;
    
      @media (max-#{$dimension}: #{$min-breakpoint}) {
        font-size: $min;
      }
    
      @if $max {
        $max-breakpoint: $max / $responsive-unitless * 100;
    
        @media (min-#{$dimension}: #{$max-breakpoint}) {
          font-size: $max;
        }
      }
    
      @if $fallback {
        font-size: $fallback;
      }
    
      font-size: $responsive;
    }
    
    .limit-min {
      @include responsive-font(3vw, 20px);
    }
    
    .limit-min-max {
      @include responsive-font(3vw, 20px, 50px);
    }
    

提交回复
热议问题