Responsive font size in CSS

前端 未结 30 3179
刺人心
刺人心 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:57

    This is partly implemented in foundation 5.

    In file _type.scss they have two sets of header variables:

    // We use these to control header font sizes
    // for medium screens and above
    
    $h1-font-size: rem-calc(44) !default;
    $h2-font-size: rem-calc(37) !default;
    $h3-font-size: rem-calc(27) !default;
    $h4-font-size: rem-calc(23) !default;
    $h5-font-size: rem-calc(18) !default;
    $h6-font-size: 1rem !default;
    
    
    // We use these to control header size reduction on small screens
    $h1-font-reduction: rem-calc(10) !default;
    $h2-font-reduction: rem-calc(10) !default;
    $h3-font-reduction: rem-calc(5) !default;
    $h4-font-reduction: rem-calc(5) !default;
    $h5-font-reduction: 0 !default;
    $h6-font-reduction: 0 !default;
    

    For medium up, they generate sizes based on the first set of variables:

    @media #{$medium-up} {
        h1,h2,h3,h4,h5,h6 { line-height: $header-line-height; }
        h1 { font-size: $h1-font-size; }
        h2 { font-size: $h2-font-size; }
        h3 { font-size: $h3-font-size; }
        h4 { font-size: $h4-font-size; }
        h5 { font-size: $h5-font-size; }
        h6 { font-size: $h6-font-size; }
    }
    

    And for default-i.e small screens, they use a second set of variables to generates CSS:

    h1 { font-size: $h1-font-size - $h1-font-reduction; }
    h2 { font-size: $h2-font-size - $h2-font-reduction; }
    h3 { font-size: $h3-font-size - $h3-font-reduction; }
    h4 { font-size: $h4-font-size - $h4-font-reduction; }
    h5 { font-size: $h5-font-size - $h5-font-reduction; }
    h6 { font-size: $h6-font-size - $h6-font-reduction; }
    

    You can use these variables and override in your custom scss file to set font sizes for respective screen sizes.

提交回复
热议问题