How to resize font-size proportionally to div size

后端 未结 4 1181
情歌与酒
情歌与酒 2021-01-18 20:32

I\'m trying to create a website where the pages resize to the windows size on the fly. While we can get images and such to resize automatically as a % of the div size. We do

相关标签:
4条回答
  • 2021-01-18 20:46

    How about using media queries?

    0 讨论(0)
  • 2021-01-18 20:59

    So you can use screen.availHeight to calculate a constant value which you can multiply with the font size.

    window.onload = function () {
        document.body.style.fontSize = (Math.ceil(screen.availHeight * parseInt(document.body.style.fontSize) / 600) + 'px';
    }
    
    0 讨论(0)
  • 2021-01-18 21:01

    even use % for text. http://w3schools.com/cssref/css_units.asp

    0 讨论(0)
  • 2021-01-18 21:05

    Whipped up some example to adjust font-size on div size change. Using percentage in the parent div and adjusting the font-size there should do the trick.

    http://jsfiddle.net/744A2/

    0 讨论(0)
提交回复
热议问题