当前位置: 首页 > 网络学院 > 网页制作基础教程 > XHTML > XHTML 语法
Writing XHTML demands a clean HTML syntax.
XHTML要求书写整洁的HTML语法
This is wrong:
这是错误的:
<table WIDTH="100%"> |
This is correct:
正确的应该是这样:
<table width="100%"> |
This is wrong:
这是错误的:
<table width=100%> |
This is correct:
正确的应该是这样:
<table width="100%"> |
This is wrong:
这是错误的:
<input checked> |
This is correct:
正确的应该是这样:
<input checked="checked" /> |
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" |
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来代替。
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" /> |
IMPORTANT Compatibility Note:
兼容提示:
To make your XHTML compatible with today's browsers, you should add an extra space before the "/" symbol.
要让XHTML兼容当前的浏览器应该在/标记前添加空格
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> |
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> <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.
下一章节你会学到更多有关XHTML文档类型定义的的内容