HTML特殊字符

Some characters like the < character, have a special meaning in HTML, and therefore cannot be used in the text.
有些字符,像<这类的,对HTML来说是有特殊意义的,所以这些字符是不允许在文本中使用的。

To display a less than sign (<) in HTML, we have to use a character entity.
要在HTML中显示(<)这个字符,我们就必须使用特殊字符。


Character Entities
特殊字符

Some characters have a special meaning in HTML, like the less than sign (<) that defines the start of an HTML tag. If we want the browser to actually display these characters we must insert character entities in the HTML source.
有一些字符对HTML来讲是有特殊意义的,像小于符号(<)是用来定义HTML头标签的。如果我们想在浏览器中显示这类字符就必须在HTML代码中插入特殊字符。

A character entity has three parts: an ampersand (&), an entity name or a # and an entity number, and finally a semicolon (;).
一个特殊字符有三个部分:一个(&)符号,一个特殊符号名称或一个#加上一个特殊数字,最后是一个分号(;)。

To display a less than sign in an HTML document we must write: &lt; or <
要显示小于符号就得在HTML中写:&lt; 或者<

The advantage of using a name instead of a number is that a name is easier to remember. The disadvantage is that not all browsers support the newest entity names, while the support for entity numbers is very good in almost all browsers.
使用名称的好处是它比用数字来的方便记忆。但不是所有浏览器都支持最新的一些特殊字符,不像特殊字符那样很好的被所有浏览器做支持。

Note that the entities are case sensitive. 
注意特殊字符需要注意大小写。

This example lets you experiment with character entities: Character Entities IE only
这个例子是让你来实验这些特殊字符的(只限IE浏览器)


Non-breaking Space
不换行空白

The most common character entity in HTML is the non-breaking space.
在HTML中最普通的特殊字符就是不换行空白了。

Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML will remove 9 of them. To add spaces to your text, use the &nbsp; character entity.
一般HTML会给你的文本除去空白,如果你在文本中有10个空格那么HTML就会去掉其中的9个。想添加空格的话就得使用&nbsp; 字符。


The Most Common Character Entities
一些很常用的特殊字符:

Result Description Entity Name Entity Number
  非换行空格 &nbsp;  
< 小于 &lt; <
> 大于 &gt; >
& “&” 号 &amp; &
" 双引号 &quot; "
' 单引号  &apos; (IE不支持) '

Some Other Commonly Used Character Entities
其他一些:

Result Description Entity Name Entity Number
cent分 &cent; ¢
£ pound镑 &pound; £
¥ yen &yen; ¥
§ section &sect; §
© copyright版权 &copy; ©
® registered 注册trademark &reg; ®
× multiplication乘 &times; ×
÷ division除 &divide; ÷

posted on 2006-11-01 09:27  Sherrys  阅读(1726)  评论(0编辑  收藏  举报

导航