Html 字体大小 - 转换为实际点大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5912528/
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 08:28:33  来源:igfitidea点击:

Font Size - Translating to actual point size

htmlcssfont-size

提问by Jim B

Quick question for everyone:

每个人的快速问题:

Does anybody know what the actual point size would be when setting the font-size to the following values:

有没有人知道将 font-size 设置为以下值时的实际点大小是多少:

  • Large
  • Larger
  • Medium
  • Small
  • Smaller
  • X-Large
  • X-Small
  • XX-Large
  • XX-Small
  • 大的
  • 更大
  • 中等的
  • 小的
  • 较小
  • 超大
  • X-小
  • XX-大
  • XX-小

采纳答案by bpeterson76

Font sizes to pixels are explained by this chart:

此图表解释了字体大小到像素:

enter image description here

在此处输入图片说明

回答by Jim B

It may vary by browser slightly but for the most part this should work:

它可能因浏览器而略有不同,但在大多数情况下,这应该有效:

Large is 18 px which is around 13.5 pt

大是 18 px,大约是 13.5 pt

Larger is 19 px which is around 14 pt

较大的是 19 px,大约 14 pt

Medium is 16 px which is around 12 pt

中号是 16 px,大约是 12 pt

Small is 13 px which is around 10 pt

小号是 13 px,大约是 10 pt

Smaller is 13 px which is around 10 pt

较小的是 13 px,大约 10 pt

X-large is 24 px which is around 18 pt

X-large 为 24 px,约为 18 pt

X-small is 10 px which is around 7.5 pt

X-small 为 10 px,约为 7.5 pt

XX-large is 32 px which is around 24 pt

XX-large 是 32 px,大约是 24 pt

XX-small is 9 px which is around 7 pt

XX-small 是 9 px,大约是 7 pt

This is based off of seeing the computed font-size style in pixels and converting from this chart. This linkmight also be helpful.

这是基于以像素为单位查看计算的字体大小样式并从此图表转换。此链接也可能有帮助。

回答by Ignacio Vazquez-Abrams

mediumis the user's preferred font size. All other values are defined by the browser. (source)

medium是用户的首选字体大小。所有其他值由浏览器定义。(来源

回答by Bjoern

Two good weblinks might answer this:

两个好的网络链接可能会回答这个问题:

回答by Ray Whitfield

If you are able to use java script then you can, using a canvas element, measure the height of a given font size. The size will return a value in pixels for the height of the font you specify. This will only work if the user has calibrated their screen: most have not but the default values are generally close for most monitor setups.

如果您能够使用 java 脚本,那么您可以使用画布元素测量给定字体大小的高度。大小将为您指定的字体的高度返回一个以像素为单位的值。这只有在用户校准了他们的屏幕时才有效:大多数没有校准,但大多数显示器设置的默认值通常很接近。

var cvs = document.getElementById("myCanvas");
var ctx = cvs.getContext("2d");
ctx.font="30px Arial";
var txt="Hello World";
var size = ctx.measureText(txt).height;