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

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

    This is actually being proposed in CSS4

    Working draft at the W3C

    Quote:

    These two properties allow a website or user to require an element’s font size to be clamped within the range supplied with these two properties. If the computed value font-size is outside the bounds created by font-min-size and font-max-size, the use value of font-size is clamped to the values specified in these two properties.

    This would actually work as following:

    .element {
        font-min-size: 10px;
        font-max-size: 18px;
        font-size: 5vw; // viewport-relative units are responsive.
    }
    

    This would literally mean, the font size will be 5% of the viewport's width, but never smaller than 10 pixels, and never larger than 18 pixels.

    Unfortunately, this feature isn't implemented anywhere yet, (not even on caniuse.com).

提交回复
热议问题