javascript pt、em、px、百分比、其他的转化率

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

Conversion rate of pt, em, px, percent, other

phpjavascriptjquerycsssize

提问by chris

More so than less I run into times when I need to use pt instead of px or em instead of pt, or whatever the case, and trying to find the right size for something bigger than say 36px is sometimes more of a pain in the .... than it should. So I basically want to make myself a little conversion calculator. However I can't seem to find anything that distinguishes what the conversion rate is from one to the other for an equal counter part of the other.

更重要的是,当我需要使用 pt 而不是 px 或 em 而不是 pt 时,或者无论如何,并且尝试为大于 36px 的东西找到合适的大小有时在 . ......比它应该的。所以我基本上想让自己做一个小的转换计算器。但是,我似乎无法找到任何可以区分另一个的相等计数器部分的转换率从一个到另一个的任何东西。

I am hoping I can find someone here who can help me with that. Basically my overall hope is to make myself a little jquery based input like calculator. I key in my px, pt, %, other and select my conversion to type and click ok.

我希望我能在这里找到可以帮助我的人。基本上我的总体希望是让自己成为一个像计算器这样的基于 jquery 的输入。我输入我的 px、pt、%、other 并选择我的转换类型并单击确定。

Creating the calculate, easy enough. The math I would have to apply on a per conversion basis not so much, and thats what I am hoping to find here so I can do it.

创建计算,很容易。我必须在每次转换的基础上应用的数学不是那么多,这就是我希望在这里找到的,所以我可以做到。

回答by Rich Bradshaw

Well,

好,

12pt = 16px = 1em = 100%

12pt = 16px = 1em = 100%

assuming you don't change the font size on the body (else the pt will be different), the dpi of your OS is set at 72 etc etc..

假设您不更改正文的字体大小(否则 pt 会有所不同),您的操作系统的 dpi 设置为 72 等。

The relationship looks like:

关系如下:

pt = 3/4*px

em = pt/12

% = pt*100/12

in this case. It's worth pointing out that using pt is wrong, unless you are printing something, and that using px, % or em is more usual.

在这种情况下。值得指出的是,使用 pt 是错误的,除非您正在打印某些东西,并且使用 px、% 或 em 更为常见。

Personally, I just use px or em. Using % or em is handy for designs where the base font size changes for smaller screens.

就个人而言,我只使用 px 或 em。使用 % 或 em 对于较小屏幕的基本字体大小更改的设计很方便。

回答by davethegr8

Ems and %s are relative values which can change depending on your context. Normally, 1em is equivalent to 16px, but if you change your body's font-size 1em is equivalent to whatever you changed it to. 1.25em is also equivalent to 125%.

Ems 和 %s 是相对值,可以根据您的上下文而改变。通常,1em 相当于 16px,但是如果您更改 body 的字体大小,则 1em 相当于您更改的任何值。1.25em 也相当于 125%。

Generally, 72pt is equivalent to 1 inch, but it shouldn't be used outside of print CSS.

通常,72pt 相当于 1 英寸,但不应在打印 CSS 之外使用。

px is also absolute but is highly dependent on the client device DPI. This varies greatly, but most devices handle px values in a perdictable manner -- 10px on a retina iphone displays the same as 10px on a pre-retina device.

px 也是绝对值,但高度依赖于客户端设备 DPI。这差别很大,但大多数设备以可预测的方式处理 px 值——视网膜 iphone 上的 10px 与视网膜前设备上的 10px 显示相同。

There's also remwhich refers to the font-size of your htmlelement. See more: http://snook.ca/archives/html_and_css/font-size-with-rem

还有remwhich 指的是html元素的字体大小。查看更多:http: //snook.ca/archives/html_and_css/font-size-with-rem

回答by Ed Heal

To make a web site truely open for all, you need to get rid of points and pixels. You need those measurements to be relative. Hence percents and ems.

要使网站真正对所有人开放,您需要摆脱点和像素。您需要这些测量值是相对的。因此,百分比和 em。

That is the best way to go.

这是最好的方法。

Lots of people (customers) has a variety of eyesight problems.

很多人(客户)有各种各样的视力问题。

Why make a web site that those people cannot easily use?

为什么要做一个那些人不能轻易使用的网站?

(Variety of standards address these problems)

(各种标准解决了这些问题)

回答by JacquesB

  • 1mm = ca 3.78 px
  • 1cm = 10 mm = ca 37.8 px
  • 1in = 25.4mm = 96px
  • 1pt = 1/72 in = 1 1/3 px
  • 1 pc = 12pt = 1/6 in = 16px
  • 1 px = 3/4pt = 1/96 in
  • 1 毫米 = 约 3.78 像素
  • 1 厘米 = 10 毫米 = 约 37.8 像素
  • 1 英寸 = 25.4 毫米 = 96 像素
  • 1pt = 1/72 英寸 = 1 1/3 像素
  • 1 pc = 12pt = 1/6 in = 16px
  • 1 像素 = 3/4pt = 1/96 英寸

These relations are fixed to each other BUT be aware that they do not correspond to physical dimensions in screen layout. 1in only correspond to an actual inch on the screen if the screen has en exact DPI at 96. There exists a wide variety of screens and devices, so only rarely will this actually be the case.

这些关系彼此固定,但请注意,它们与屏幕布局中的物理尺寸不对应。如果屏幕的 DPI 为 96,则 1in 仅对应于屏幕上的实际英寸。 屏幕和设备种类繁多,因此实际情况很少见。

1px does not always correspond to a physical pixel either. For high dpi devices (eg "retina" displays), the browser may convert px units to multiples of physical pixels, eg. 1px = 4x4 physical pixels.

1px 也不总是对应于一个物理像素。对于高 dpi 设备(例如“视网膜”显示器),浏览器可能会将 px 单位转换为物理像素的倍数,例如。1px = 4x4 物理像素。

In print, the units in, cm, mm actually do correspond to the physical units. The px unit though, does not have any relation to screen pixels (or dpi) when used for a print stylesheet. It is just defined as 1/96 of an inch.

在印刷中,单位 in、cm、mm 实际上确实与物理单位相对应。但是,当用于打印样式表时,px 单位与屏幕像素(或 dpi)没有任何关系。它只是定义为 1/96 英寸。

The relative units (em, ex, %) cannot be converted into absolute units (px, cm, mm, in, pc, pt) because the relative units depends on the current font size.

相对单位(em、ex、%)不能转换为绝对单位(px、cm、mm、in、pc、pt),因为相对单位取决于当前的字体大小。