Font size auto adjust to fit

后端 未结 7 1831
夕颜
夕颜 2020-12-09 09:06

I\'m trying to do what the title says. I\'ve seen that font-size can be a percentage. So my guess was that font-size: 100%; would do it, but no.

7条回答
  •  孤街浪徒
    2020-12-09 09:44

    A bit late but this is how I approach this problem:

    document.body.setScaledFont = function() {
        var f = 0.35, s = this.offsetWidth, fs = s * f;
        this.style.fontSize = fs + '%';
        return this
    }
    document.body.setScaledFont();
    

    The base document font is now set.

    For the rest of your elements in the dom set font sizes as % or em and they will scale proportionately.

提交回复
热议问题