Difference between XHTML da HTML
- Previous page XHTML Why
- Next page XHTML grammar
通过开始编写严格的HTML,你可以为XHTML做好准备。
如何为XHTML做好准备
XHTML与HTML 4.01标准没有太多的不同。
所以将你的代码升级至 4.01 是个不错的开始。我们的完整的《HTML 4.01参考手册》会帮助你做到这一点。
另外,你应该马上使用小写字母编写HTML代码,同时绝不要养成忽略类似 </p> 标签的坏习惯。
祝您可以愉快地编码!
最主要的不同:
- XHTML元素必须被正确地嵌套。
- XHTML元素必须被关闭。
- 标签名必须用小写字母。
- XHTML文档必须拥有根元素。
元素必须被正确地嵌套
在HTML中,某些元素可以像这样彼此不正确地嵌套:
<b><i>This text is bold and italic</b>
</i>
在XHTML中,所有的元素必须像这样彼此正确地嵌套:
<b><i>This text is bold and italic</i></b>
提示:在嵌套列表中一个容易犯的错误,是忘记内部列表必须位于 li 元素中,就像下面这样:
This is incorrect:
<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>
注意:在正确代码的例子中,我们在 </ul> 之后插入了一个 </li> 标签。
XHTML元素必须被关闭
非空标签必须使用结束标签。
This is incorrect:
<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>
空标签也必须被关闭
空标签也必须使用结束标签,或者其开始标签必须使用/>
结尾。
This is incorrect:
A break: <br> A horizontal rule: <hr> An image: <img src="happy.gif" alt="Happy face">
This is correct:
A break: <br/>
A horizontal rule: <hr/>
An image: <img src="happy.gif" alt="Happy face"/>
XHTML元素必须小写
XHTML规范定义:标签名和属性对大小写敏感。
This is incorrect:
<BODY>
<P>
This is a paragraph</P>
</BODY>
This is correct:
<body>
<p>
This is a paragraph</p>
</body>
An XHTML document must have a root element
All XHTML elements must be nested within the <html> root element. All other elements can have child elements. Child elements must be paired and nested within their parent elements. The basic document structure is as follows:
<html>
<head> ... </head> <body> ... </body></html>
- Previous page XHTML Why
- Next page XHTML grammar