[XHTML Tutorial] 走向XHTML标准 (3)(Differences Between XHTML And HTML)

原文地址:http://www.w3schools.com/xhtml/xhtml_html.asp
翻译:范维肖

You can prepare yourself for XHTML by starting to write strict HTML.
你可以通过开始书写严格的HTML代码来为你的XHML之路做准备

How To Get Ready For XHTML
如何开始XHTML呢?
XHTML is the next generation of HTML, but it will of course take some time before browsers and other software products are ready for it.
XHTML是HTML的下一代语言,当然,在新的浏览器和其他的相关软件产品出现之前,它将延迟一段时间才能普及。
In the meantime there are some important things you can do to prepare yourself for it. As you will learn from this tutorial, XHTML is not very different from HTML 4.01, so bringing your code up to 4.01 standards is a very good start. Our complete HTML 4.01 reference can help you with that.
其间,有一些重要的事情你能够去做来为它的学习做准备。就像你可以从这篇指南学到的东西一样,XHTML不是与HTML4.01有很多不同的,所以把你的代码改写程4.01标准是一种非常好的开始,我们完整的HTML4.01参考可以帮助你解决这个问题。
In addition, you should start NOW to write your HTML code in lowercase letters, and NEVER make the bad habit of skipping end tags like the </p>.
另外,现在你应该开始用小写字母来书写你的HTML代码了,并且永远不要再像以前那样有跳过像</p>这样的结尾标记的坏习惯了。
Happy coding!
陶醉于编码之中吧!

The Most Important Differences:
两者最主要的不同:
XHTML elements must be properly nested
XHTML documents must be well-formed
Tag names must be in lowercase
All XHTML elements must be closed
XHTML元素必须正确的嵌套
XHTML文档必须有良好的格式
标记的名字必须用小写字母
左右的XHTML元素都必须有关闭符

Elements Must Be Properly Nested
元素(标记)必须被正确的嵌套
In HTML some elements can be improperly nested within each other like this:
在HTML中,有些标记能够非正确的相互嵌套,就像这样:

<b><i>This text is bold and italic</b></i>

In XHTML all elements must be properly nested within each other like this:
在XHTML中所有的标记必须被正确的嵌套,像这样:
<b><i>This text is bold and italic</i></b>

Note: A common mistake in nested lists, is to forget that the inside list must be within an li element, like this:
注意:在列表嵌套的时候大家经常会犯一个错误,那就是忘记了插入的新的列表必须在一个<li>标记中,像这样
<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  <li>Milk</li>
</ul>

This is correct:
正确的写法
<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  </li>
  <li>Milk</li>
</ul>


Notice that we have inserted a </li> tag after the </ul> tag in the "correct" code example.
在这段正确的代码示例中,注意到我们在</ul>之后加了一个</li>标记吗?

Documents Must Be Well-formed
文档必须格式良好
All XHTML elements must be nested within the <html> root element. All other elements can have sub (children) elements. Sub elements must be in pairs and correctly nested within their parent element. The basic document structure is:
所有的XHTML标记必须被嵌套使用在<html>根标记之中。所有其他的标记能有自己的子标记。位于父标记之内的子标记也必须成对的而且正确的嵌套使用。一个网页的基本结构是这样:

<html>
<head> ... </head>
<body> ... </body>
</html>


Tag Names Must Be In Lower Case
标记的名字必须用小写字母
This is because XHTML documents are XML applications. XML is case-sensitive. Tags like <br> and <BR> are interpreted as different tags.
这是因为XHTML文档是XML的应用程序,XML是大小写敏感的,像<br>和<BR>是会被认为为两种不共的标记的。
This is wrong:
错误的:
<BODY>
<P>This is a paragraph</P>
</BODY>

This is correct:
正确的

<body>
<p>This is a paragraph</p>
</body>

All XHTML Elements Must Be Closed
所有的XHTML标记都必须有关闭符
Non-empty elements must have an end tag.
非空的标记必须有一个关闭符。
This is wrong:
这是错误的:

<p>This is a paragraph
<p>This is another paragraph

This is correct:
这才是正确的

<p>This is a paragraph</p>
<p>This is another paragraph</p>

Empty Elements Must Also Be Closed
空标记也必须有关闭符
Empty elements must either have an end tag or the start tag must end with />.
空标记必须有关闭符或以开始符加上 />来结束
This is wrong:
错误的代码

This is a break<br>
Here comes a horizontal rule:<hr>
Here's an image <img src="happy.gif" alt="Happy face">

This is correct:
正确的:

This is a break<br />
Here comes a horizontal rule:<hr />
Here's an image <img src="happy.gif" alt="Happy face
" />

IMPORTANT Compatibility Note:
关于兼容性的重要的注释:
To make your XHTML compatible with today's browsers, you should add an extra space before the "/" symbol like this: <br  />, and this: <hr  />.
为了使你的XHTML能够兼容现在的浏览器,你必须在/符号之前加一个特殊的空格,就像这样:<br  /><hr  />

(转载请注明出处)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值