Html 将摄氏度符号编码到网页中的最佳方法?

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

Best way to encode Degree Celsius symbol into web page?

htmlsymbols

提问by Evanss

How should I encode special characters into web pages? For instance I need this symbol ℃, which I used just by copying and pasting the character as I can see it now. This worked for the desktop browsers I checked with and also on iPad and iPhone but nothing is displayed on a Blackberry I used for testing. Is there a standard best practice for this?

我应该如何将特殊字符编码到网页中?例如我需要这个符号℃,我只是通过复制和粘贴字符来使用它,就像我现在看到的那样。这适用于我检查过的桌面浏览器以及 iPad 和 iPhone,但在我用于测试的 Blackberry 上没有显示任何内容。是否有标准的最佳实践?

http://www.fileformat.info/info/unicode/char/2103/browsertest.htm

http://www.fileformat.info/info/unicode/char/2103/browsertest.htm

回答by Nix

Try to replace it with °, and also to set the charset to utf-8, as Martin suggests.

°正如 Martin 建议的那样,尝试将其替换为, 并将字符集设置为 utf-8。

°Cwill get you something like this:

°C会给你这样的东西:

Degrees Celsius

摄氏度

回答by Jukka K. Korpela

If you really want to use the DEGREE CELSIUS character “℃”, then copy and paste is OK, provided that your document is UTF-8 encoded and declared as such in HTTP headers. Using the character reference ℃would work equally well, and would work independently of character encoding, but the source would be much less readable.

如果你真的想使用摄氏度字符“℃”,那么复制和粘贴就可以了,前提是你的文档是 UTF-8 编码的,并在 HTTP 标头中声明为这样。使用字符引用℃同样可以工作,并且可以独立于字符编码工作,但源代码的可读性要差得多。

The problem with Blackberry is most probably a font issue. I don't know about fonts on Blackberry, but the font reperttheitroade might be limited. There's nothing you can do about this in HTML, but you can use CSS, possibly with @font face.

黑莓的问题很可能是字体问题。我不了解 Blackberry 上的字体,但字体库可能有限。在 HTML 中您无能为力,但您可以使用 CSS,可能还带有@font face.

But there is seldom any reason to use the DEGREE CELSIUS. It is a compatibility character, included in Unicode due to its use in East Asian writing. The Unicode Standard explicitly says in Chapter 15(section 15.2, page 497):

但很少有理由使用摄氏度。它是一个兼容字符,由于在东亚文字中使用而包含在 Unicode 中。Unicode 标准在第 15 章(第 15.2 节,第 497 页)中明确指出:

“In normal use, it is better to represent degrees Celsius “°C” with a sequence of U+00B0 degree sign + U+0043 latin capital letter c, rather than U+2103 degree celsius.”

“在正常使用中,最好用 U+00B0 度符号 + U+0043 拉丁大写字母 c 的序列来表示摄氏度“°C”,而不是 U+2103 摄氏度。”

The degree sign “°” can be entered in many ways, including the entity reference `°, but normally it is best to insert it as a character, via copy and paste or otherwise. On Windows, you can use Alt 0176.

度数符号“°”可以通过多种方式输入,包括实体引用“°”,但通常最好通过复制和粘贴或其他方式将其作为字符插入。在 Windows 上,您可以使用 Alt 0176。

Caveat: Some browsers may treat the degree sign as allowing a line break after it even when no space intervenes, putting “°” and the following “C” on separate lines. There are different ways to prevent this. A simple and effective method is this: <nobr>42 °C</nobr>.

警告:一些浏览器可能会将度数符号视为允许在它之后换行,即使没有空格介入,将“°”和后面的“C”放在单独的行上。有不同的方法可以防止这种情况发生。一个简单有效的方法是这样的:<nobr>42 °C</nobr>.

回答by Persijn

Using supon the letter "o" and a capital "C"

在字母“o”和大写“C”上使用sup

<sup>o</sup>C

Should work in all browsers and IE6+

应该适用于所有浏览器和 IE6+

回答by Saba Ahang

I'm not sure why this hasn't come up yet but why don't you use &#8451;(℃) or &#8457;(℉) for Celsius and Fahrenheit respectively!

我不确定为什么这还没有出现,但为什么不分别使用&#8451;(℃) 或&#8457;(℉) 表示摄氏和华氏!

回答by Martin Risell Lilja

Add a metatag to your header

将元标记添加到您的标题

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

This expands the amount of characters you can use.

这扩大了您可以使用的字符数量。

回答by Johan Hoffsten

  1. The degree sign belongs to the number, and not to the "C". You can regard the degree sign as a number symbol, just like the minus sign.
  2. There shall notbe any space between the digits and the degree sign.
  3. There shallbe a non-breaking space between the degree sign and the "C".
  1. 度数符号属于数字,而不属于“C”。您可以将度数符号视为数字符号,就像减号一样。
  2. 有应为数字和符号度之间的任何空间。
  3. 这里是程度的标志和“C”之间的非打破空间。