如何将字体大小按比例调整为div大小 [英] How to resize font-size proportionally to div size
问题描述
我正在尝试创建一个网站,其中的网页调整为窗口大小在飞行。虽然我们可以得到图像等等自动调整大小为div大小的%。我们似乎不能调整div内的文本大小到容器的相对%。
此功能需要在浏览器窗口本身调整大小时工作,而无需刷新页面。
网站是基本的,使用js,css,html。可以理解最简单的方法,但任何解决方案是梦幻般的。
感谢
因此,您可以使用screen.availHeight一个常数值,可以乘以字体大小。
window.onload = function(){
/ pre>
文档。 body.style.fontSize =(Math.ceil(screen.availHeight * parseInt(document.body.style.fontSize)/ 600)+'px';
}
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 not seem to be able to resize the text within a div to a relative % of the container.
This feature would need to work as the browser window itself is resized, without having to refresh the page.
The site is basic and is using js,css, html. The simplest method possible would be appreciated, but any solution is fantastic.
Thanks
解决方案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'; }
这篇关于如何将字体大小按比例调整为div大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!