当前位置: 首页 > 网络学院 > 网页制作基础教程 > XHTML > XHTML 对比 HTML
You can prepare yourself for XHTML by starting to write strict HTML.
你可以开始通过书写严密的HTML代码来为你的XHML之旅做好准备
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代码,还有千万别漏掉结束标签。
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> |
This is correct:
这才是正确的:
<ul> |
Notice that we have inserted a </li> tag after the </ul> tag in the "correct" code example.
在这段正确的代码示例中,</ul>后面加入了</li>标签
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> |
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> |
This is correct:
这才是正确的:
<body> |
Non-empty elements must have an end tag.
非空元素必须得有结束标签
This is wrong:
这是错误的写法:
<p>This is a paragraph |
This is correct:
这是正确的:
<p>This is a paragraph</p> |
Empty elements must either have an end tag or the start tag must end with />
.
空标签同样也得关闭,可以是在开始标签后加上/>
This is wrong:
这是错误的写法:
This is a break<br> |
This is correct:
正确的是这样:
This is a break<br /> 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 /> 这样的标签在"/"前加上额外的空格