How do I implement responsive typography with Bootstrap 4?

后端 未结 5 1300
独厮守ぢ
独厮守ぢ 2021-01-12 05:29

I\'m building a responsive web app with Bootstrap 4. I want the font size of all text to be reduced on mobile devices compared to desktop, so I added the following to my bas

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 06:10

    Here is an alternative approach with loop

    @import "bootstrap/functions";
    @import "bootstrap/variables";
    @import "bootstrap/mixins";
    
    $font-sizes: (
        html: ( xs: 1rem, sm: 1.2rem, md: 1.3rem),
      );
    
    @each $breakpoint in map-keys($grid-breakpoints) {
      @include media-breakpoint-up($breakpoint) {
        $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
    
        @each $name, $values in $font-sizes {
          @each $n, $value in $values {
            @if($infix == "-#{$n}" or ($infix == "" and $n == 'xs')) {
              #{$name} { font-size: $value; }
            }
          }
        }
      }
    }
    

提交回复
热议问题