[XHTML Tutorial] 走向XHTML标准 (4)(XHTML Syntax)

类别:网站制作 点击:0 评论:0 推荐:
原文地址:http://www.w3schools.com/xhtml/xhtml_syntax.asp
翻译:范维肖

Writing XHTML demands a clean HTML syntax.
我们需要用干净的HTML语法来书写XHTML页面
Some More XHTML Syntax Rules:
更多的XHTML语法规定:

Attribute Names Must Be In Lower Case
属性名称必须使用小写

This is wrong:
错误代码:
<table WIDTH="100%">
This is correct:
正确代码:
<table width="100%">

Attribute Values Must Be Quoted
属性值必须加引号

This is wrong:
错误代码:
<table width=100%>
This is correct:
正确代码:
<table width="100%">

Attribute Minimization Is Forbidden
属性的简写方法是被禁止的
This is wrong:

<dl compact>
<input checked>
<input readonly>
<input disabled>
<option selected>
<frame noresize>

This is correct:

<dl compact="compact">
<input checked="checked" />
<input readonly="readonly" />
<input disabled="disabled" />
<option selected="selected" />
<frame noresize="noresize" />

Here is a list of the minimized attributes in HTML and how they should be written in XHTML:
在HTML中简写的属性和其在XHTML中应该怎样书写的列表:
HTML XHTML 
compact compact="compact" 
checked checked="checked" 
declare declare="declare" 
readonly readonly="readonly" 
disabled disabled="disabled" 
selected selected="selected" 
defer defer="defer" 
ismap ismap="ismap" 
nohref nohref="nohref" 
noshade noshade="noshade" 
nowrap nowrap="nowrap" 
multiple multiple="multiple" 
noresize noresize="noresize" 

The id Attribute Replaces The name Attribute
使用id属性来替代name属性
HTML 4.01 defines a name attribute for the elements a, applet, frame, iframe, img, and map. In XHTML the name attribute is deprecated. Use id instead.
对于a, applet, frame, iframe, img和map,HTML 4.01中定义了一个name属性,在XHTML中是不赞成这样做的,使用id来代替name。
This is wrong:

<img src="picture.gif" name="picture1" />

This is correct:

<img src="picture.gif" id="picture1" />

Note: To interoperate with older browsers for a while, you should use both name and id, with identical attribute values, like this:
注意:为了版本比较低的浏览器的存在,你应该同时使用name和id属性,并且它们两个的值应该是相同的,就像这样:
<img src="picture.gif" id="picture1" name="picture1" />

The Lang Attribute
lang属性
The lang attribute applies to almost every XHTML element. It specifies the language of the content within an element.
lang属性可以应用于几乎所有的XHTML元素。它指定了元素中内容的语言集。
If you use the lang attribute in an element, you must add the xml:lang attribute, like this:
如果你像在一个元素中应用lang属性,你必须加上xml:lang属性,像这样:
<div lang="no" xml:lang="no">Heia Norge!</div>
Mandatory XHTML Elements
强制性的XHTML元素
All XHTML documents must have a DOCTYPE declaration. The html, head and body elements must be present, and the title must be present inside the head element.
所有的XHTML文档都必须有一个DOCTYPE声名。html、head和body元素必须出现,并且title必须出现在head里
This is a minimum XHTML document template:
这是一个最小的XHTML文档模板
<!DOCTYPE Doctype goes here>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title goes here</title>
</head><body>
Body text goes here
</body></html>
Note: The DOCTYPE declaration is not a part of the XHTML document itself. It is not an XHTML element, and it should not have a closing tag.
注意:DOCTYPE声明并不是XHTML文档自身的一部分。它也不是XHTML元素,它也没有关闭符。
Note: The xmlns attribute inside the <html> tag is required in XHTML. However, the validator on w3.org does not complain when this attribute is missing in an XHTML document. This is because "xmlns=http://www.w3.org/1999/xhtml" is a fixed value and will be added to the <html> tag even if you do not include it.
注意:XHTML文档要求xmlns属性出现在html标记中。然而,w3.org的有效性检查器不会对这个属性没有出现在你的XHTML文档中而报告错误。这是因为"xmlns=http://www.w3.org/1999/xhtml"是一个固定的值,即使你的文档里没有包含它,它也会自动加上的。
You will learn more about the XHTML document type definition in the next chapter.
在下一章的学习中你将学到更多的XHTL文件类型定义的知识。

(转载请注明出处)

本文地址:http://com.8s8s.com/it/it30932.htm