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

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

    CSS min() and max() have fairly good usage rates in 2020.

    The code below uses max() to get the largest of the [variablevalue] and [minimumvalue] and then passes that through to min() against the [maximumvalue] to get the smaller of the two. This creates an allowable font range (3.5rem is minimum, 6.5rem is maximum, 6vw is used only when in between).

    font-size: min(max([variablevalue], [minimumvalue]), [maximumvalue]);
    font-size: min(max(6vw, 3.5rem), 6.5rem);
    

    I'm using this specifically with font-awesome as a video-play icon over an image within a bootstrap container element where max-width is set.

提交回复
热议问题