Html 为什么字体大小不会随着浏览器放大而改变?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7907760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:15:49  来源:igfitidea点击:

Why the font size won't change with browser zoom in?

htmlcssgoogle-chromeweb

提问by lucemia

In most of websites, while I change the zoom level of browsers, the font size will also increase and help user to see them. For some reasons, that just won't work on my new website. While I change the zoom level of the browser, everything changes but all font size keep the same. Is there a css or html property that I can use to control this behavior? Thanks

在大多数网站中,当我改变浏览器的缩放级别时,字体大小也会增加并帮助用户看到它们。由于某些原因,这在我的新网站上不起作用。当我更改浏览器的缩放级别时,一切都会发生变化,但所有字体大小都保持不变。是否有可用于控制此行为的 css 或 html 属性?谢谢

here is an example: http://ca.skywatcher.com/index.php

这是一个例子:http: //ca.skywatcher.com/index.php

回答by Lycha

The problem is that you have set -webkit-text-size-adjust: none;for the body in layout.css. Changing it to -webkit-text-size-adjust: auto;allows the zooming of the fonts along with the page.

问题是你已经-webkit-text-size-adjust: none;layout.css. 将其更改为-webkit-text-size-adjust: auto;允许字体与页面一起缩放。

Edit: Corrected the CSS. Should be autonot 0

编辑:更正了 CSS。应该auto不是0

回答by Glen Solsberry

Fonts using a specific pixel size are not relative (along with several others). Zooming changes that relative information.

使用特定像素大小的字体不是相对的(以及其他几个)。缩放会改变相关信息。

From http://www.westciv.com/style_master/academy/css_tutorial/properties/values.html

来自http://www.westciv.com/style_master/academy/css_tutorial/properties/values.html

Name        Abbrev. Explanation                             Relative?
em          em      The height of a font                    yes
ex          ex      The height of the letter x in a font    yes
pica        pc      1 pica is 12 points                     no
point       pt      1/72 of an inch                         no
pixel       px      One dot on a screen                     no
millimeter  mm      Printing unit                           no
centimeter  cm      Printing unit                           no
inch        in      Printing unit                           no

回答by Brian Driscoll

If you're using a fixed-point width for your font-size settings (e.g.: pixels), then your font size will remain unchanged when the user zooms. If you want the font to enlarge or diminish when the user zooms in/out, then consider using emas your unit (1 em = 100% of the default font size on the user's machine).

如果您对字体大小设置使用定点宽度(例如:像素),那么当用户缩放时您的字体大小将保持不变。如果您希望在用户放大/缩小时字体放大或缩小,请考虑使用em作为您的单位(1 em = 用户机器上默认字体大小的 100%)。