当前位置: 首页 > 网络学院 > 网页制作基础教程 > XHTML > XHTML 对比 HTML

XHTML
XHTML 介绍
为什么使用 XHTML
XHTML 对比 HTML
XHTML 语法
XHTML DTD
怎样转换成 XHTML
XHTML 校验
XHTML 模块
XHTML 属性
XHTML 事件
XHTML 摘要

XHTML 对比 HTML


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 638 ::
收藏到网摘: n/a

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


How To Get Ready For XHTML
怎样为XHTML做好准备

XHTML is not very different from HTML 4.01, so bringing your code up to the 4.01 standard is a good start. Our complete HTML 4.01 reference can help you with that.
XHTML与HTML的区别并不是很大,因此熟悉HTML4.01标准代码对学习XHTML来讲非常有意义。W3S提供的HTML 4.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代码,还有千万别漏掉结束标签。


The Most Important Differences:
最主要的区别:

  • XHTML elements must be properly nested
    XHTML元素必须合理嵌套
  • XHTML documents must be well-formed
    XHTML文档形式上必须符合规范
  • Tag names must be in lowercase
    标签必须使用小写
  • All XHTML elements must be closed
    所有的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 a 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) All

登陆 | 还没注册?