XHTML 对比 HTML

为什么使用 XHTML XHTML 语法

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值