Font scaling based on width of container

后端 未结 30 2980
面向向阳花
面向向阳花 2020-11-21 04:35

I\'m having a hard time getting my head around font scaling.

I currently have a website with a body font-size of 100%. 100% of what though? This seems t

30条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 05:26

    Always have your element with this attribute:

    JavaScript: element.style.fontSize = "100%";

    or

    CSS: style = "font-size: 100%;"

    When you go fullscreen, you should already have a scale variable calculated (scale > 1 or scale = 1). Then, on fullscreen:

    document.body.style.fontSize = (scale * 100) + "%";
    

    It works nicely with little code.

提交回复
热议问题