如何将字体大小按比例调整为div大小 [英] How to resize font-size proportionally to div size

查看:1127
本文介绍了如何将字体大小按比例调整为div大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个网站,其中的网页调整为窗口大小在飞行。虽然我们可以得到图像等等自动调整大小为div大小的%。我们似乎不能调整div内的文本大小到容器的相对%。



此功能需要在浏览器窗口本身调整大小时工作,而无需刷新页面。



网站是基本的,使用js,css,html。可以理解最简单的方法,但任何解决方案是梦幻般的。



感谢

解决方案

因此,您可以使用screen.availHeight一个常数值,可以乘以字体大小。

  window.onload = function(){
文档。 body.style.fontSize =(Math.ceil(screen.availHeight * parseInt(document.body.style.fontSize)/ 600)+'px';
}
/ pre>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆