Responsive font-size/weight

后端 未结 4 893
轻奢々
轻奢々 2021-02-04 21:35

I can make my images/divs responsive by using percentages.

How can I make the font-size responsive to different screen sizes?

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 22:30

    I stumbled across this problem recently and I wrote a solution for it that suits my needs. Maybe you will find that you can incorporate it into your CSS as well.

    github.com/wadim/responsive-font-size

    Usage:

    @import "responsive-font-size";
    
    p {
        @include responsive-font-size (
            $min-font-size: 1.8em,
            $max-font-size: 3.7em,
            $min-screen-width: 640px,
            $max-screen-width: 1200px,
            $font-size-step: 0.3em /* optional parameter, default: 0.1em */
        );
    } 
    

    It basically says:

    • for screen width smaller than 640px I want the font-size to be 1.8em
    • for screen width greater than 1200px I want it to be 3.7em
    • scale the font appropriately in between
    • don't bother changing the font size by less than 0.3em

提交回复
热议问题