javascript - 根据窗口高度更改字体大小

标签 javascript jquery css html fonts

是否可以根据浏览器窗口的高度(不是使用媒体查询的宽度)更改标题的 CSS font-sizeline-height

最佳答案

是的。您可以使用 the vh (viewport height) unit 单独使用 CSS 来完成此操作:

vh unit
Equal to 1% of the height of the initial containing block.

font-size: 1vh;     /* Equal to 1/100th of the viewport height. */
font-size: 50vh;    /* Equal to 1/2 of the viewport height. */
font-size: 100vh;   /* Equal to the viewport height. */

这同样适用于line-height:

line-height: 1vh;     /* Equal to 1/100th of the viewport height. */
line-height: 50vh;    /* Equal to 1/2 of the viewport height. */
line-height: 100vh;   /* Equal to the viewport height. */

演示

html, body, h1 { margin: 0; }

h1 {
  font-size: 50vh;
  line-height: 100vh;
  text-align: center;
}
<h1>Hello, world!</h1>

关于javascript - 根据窗口高度更改字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28113987/

相关文章:

javascript - Internet Explorer 中的 jQuery UI 对话框和 maxHeight

javascript - rails rjs 修改主体中的样式以添加边距

java - java 和 javascript 中的正则表达式

jquery - 无法正确定位清除按钮

html - block 内的文本显示不正确

HTML 显示一些图像是倒置的,有些图像不是

javascript - 如何让 Javascript 难以理解

javascript - 覆盖 typescript 中的函数返回类型

javascript - 如何在多选下拉列表中输出所有选定选项的文本而不使用php javascript提交

javascript - AJAX jQuery 通过按钮单击响应进行迭代