Best way to encode Degree Celsius symbol into web page?

前端 未结 7 1338
鱼传尺愫
鱼传尺愫 2020-12-13 05:15

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 wo

相关标签:
7条回答
  • 2020-12-13 05:53

    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.

    The problem with Blackberry is most probably a font issue. I don’t know about fonts on Blackberry, but the font repertoire might be limited. There’s nothing you can do about this in HTML, but you can use CSS, possibly with @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):

    “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.”

    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.

    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>.

    0 讨论(0)
  • 2020-12-13 05:54

    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!

    0 讨论(0)
  • 2020-12-13 06:03

    Using sup on the letter "o" and a capital "C"

    <sup>o</sup>C

    Should work in all browsers and IE6+

    0 讨论(0)
  • 2020-12-13 06:04
    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 not be any space between the digits and the degree sign.
    3. There shall be a non-breaking space between the degree sign and the "C".
    0 讨论(0)
  • 2020-12-13 06:07

    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.

    0 讨论(0)
  • 2020-12-13 06:14

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

    &deg;C will get you something like this:

    Degrees Celsius

    0 讨论(0)
提交回复
热议问题