<!ELEMENT BODY O O (%block;|SCRIPT)+ +(INS|DEL) -- document body --> <!ATTLIST BODY %attrs; -- %coreattrs, %i18n, %events -- %Script; #IMPLIED -- the document has been loaded -- onunload %Script; #IMPLIED -- the document has been removed -- >
Start tag: optional, End tag: optional
开始标签:可选,结束标签:可选
Attribute definitions
属性定义
Attributes defined elsewhere
在其他地方定义的属性
The body of a document contains the document's content. The content may be presented by a user agent in a variety of ways. For example, for visual browsers, you can think of the body as a canvas where the content appears: text, images, colors, graphics, etc. For audio user agents, the same content may be spoken. Since style sheets are now the preferred way to specify a document's presentation, the presentational attributes of BODY have been deprecated.
文 档的BODY承载文档的内容。用户代理可能以多种方式显示BODY的内容。例如,对于可视化浏览器,可以认为BODY是一个用于绘制诸如:文本,图片,颜 色,图像等的画布。对于音频浏览器,同样的内容将会被朗读出来。现在,由于样式表作为推荐的控制文档展现的工具,BODY的所有展现相关的属性都是不推荐 的。
DEPRECATED EXAMPLE:
The following HTML fragment illustrates the use of the deprecated attributes. It sets the background color of the canvas to white, the text foreground color to black, and the color of hyperlinks to red initially, fuchsia when activated, and maroon once visited.
不推荐的示例:
下面的HTML片段展示了不推荐属性的用法。它设置画布的背景色为白色,文本的前景色为黑色以及未被访问的超链接为红色,激活的超链接为紫色,访问过的超链接为褐紫色。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <TITLE>A study of population dynamics</TITLE> </HEAD> <BODY bgcolor="white" text="black" link="red" alink="fuchsia" vlink="maroon"> ... document body... </BODY> </HTML>
Using style sheets, the same effect could be accomplished as follows:
采用样式表,可以获得同样的效果:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE>A study of population dynamics</TITLE> <STYLE type="text/css"> BODY { background: white; color: black} A:link { color: red } A:visited { color: maroon } A:active { color: fuchsia } </STYLE> </HEAD> <BODY>
... document body... </BODY> </HTML>
Using external (linked) style sheets gives you the flexibility to change the presentation without revising the source HTML document:
外部(链接的)样式表的使用提供了在不修改HTML文档源代码的情况下改变展现效果的灵活性:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <TITLE>A study of population dynamics</TITLE> <LINK rel="stylesheet" type="text/css" href="smartstyle.css"> </HEAD> <BODY> ... document body... </BODY> </HTML>
Framesets and HTML bodies. Documents that contain framesets replace the BODY element by the FRAMESET element. Please consult the section on frames for more information.
Frameset和HTML BODY。在承载frameset的文档中FRAMESET元素替代了BODY元素。有关框架的更多信息请参阅本规范的相应部分。
Attribute definitions
属性定义
<P id="myparagraph"> This is a uniquely named paragraph.</P> <P id="yourparagraph"> This is also a uniquely named paragraph.</P>
The id attribute has several roles in HTML:
在HTML中id属性拥有多个角色,具体如下:
The class attribute, on the other hand, assigns one or more class names to an element; the element may be said to belong to these classes. A class name may be shared by several element instances. The class attribute has several roles in HTML:
在另一方面,class属性为一个元素赋予一个或多个class名字;也可以说成是该元素属于这些class。一个class名字可以被多个元素实例共享。class属性在HTML中拥有多个角色:
In the following example, the SPAN element is used in conjunction with the id and class attributes to markup document messages. Messages appear in both English and French versions.
下面例子中,SPAN元素与id和class属性联合使用来标记文档消息。这些消息同时拥有英文和法文版本。
<!-- English messages --> <P><SPAN id="msg1" class="info" lang="en">Variable declared twice</SPAN> <P><SPAN id="msg2" class="warning" lang="en">Undeclared variable</SPAN> <P><SPAN id="msg3" class="error" lang="en">Bad syntax for variable name</SPAN>
<!-- French messages --> <P><SPAN id="msg1" class="info" lang="fr">Variable déclarée deux fois</SPAN> <P><SPAN id="msg2" class="warning" lang="fr">Variable indéfinie</SPAN> <P><SPAN id="msg3" class="error" lang="fr">Erreur de syntaxe pour variable</SPAN>
The following CSS style rules would tell visual user agents to display informational messages in green, warning messages in yellow, and error messages in red:
下面的CSS样式规则告知可视化浏览器用绿色显示提示性消息,用黄色显示警告消息以及用红色显示错误消息:
SPAN.info { color: green } SPAN.warning { color: yellow } SPAN.error { color: red }
Note that the French "msg1" and the English "msg1" may not appear in the same document since they share the same id value. Authors may make further use of the id attribute to refine the presentation of individual messages, make them target anchors, etc.
请注意,法文的“msg1”和英文的“msg1”由于共享了同一个id值,不可以在同一个文档中同时出现。作者可以进一步应用id属性来改进单个消息的展现,以及将它们作为目标锚定点等。
Almost every HTML element may be assigned identifier and class information.
几乎所有的HTML元素都可以被赋予标识符以及class信息。
Suppose, for example, that we are writing a document about a programming language. The document is to include a number of preformatted examples. We use the PRE element to format the examples. We also assign a background color (green) to all instances of the PRE element belonging to the class "example".
例如,设想一下我们正在撰写一个关于编程语言的文档。在文档中准备包含一些预格式化处理过的示例。我们使用PRE元素来格式化这些示例。对于属于class"example"的PRE元素实例的背景颜色设置成绿色。
<HEAD> <TITLE>
... document title ...
</TITLE> <STYLE type="text/css"> PRE.example { background : green } </STYLE> </HEAD> <BODY> <PRE class="example" id="example-1"> ...example code here... </PRE> </BODY>
By setting the id attribute for this example, we can
(1) create a hyperlink to it and
(2) override class style information with instance style information.
通过为该示例设置id属性,我们可以
(1)创建一个链接到它的超链接以及
(2)用实例样式信息覆盖class样式信息。
Note. The id attribute shares the same name space as the name attribute when used for anchor names. Please consult the section on anchors with id for more information.
注释。在作为锚定点使用时,id属性和name属性共享同一个名字空间。请参阅”使用id锚定部分“以获取更多信息。
Certain HTML elements that may appear in BODY are said to be "block-level" while others are "inline" (also known as "text level"). The distinction is founded on several notions:
在BODY中允许出现的HTML元素中有一部分被称为块级别元素,另一部分称为行内元素(也叫做文本级别元素)。他们的区别表现在如下方面:
Style sheets provide the means to specify the rendering of arbitrary elements, including whether an element is rendered as block or inline. In some cases, such as an inline style for list elements, this may be appropriate, but generally speaking, authors are discouraged from overriding the conventional interpretation of HTML elements in this way.
样式表提供了,包括指定一个元素是作为块级别还是行内来展现在内的,控制元素绘制的方法。在一些情况下,如列表元素的行内样式,这样做可能是合适的,但一般来说,作者不应该覆盖HTML元素约定俗成的解释。
The alteration of the traditional presentation idioms for block level and inline elements also has an impact on the bidirectional text algorithm. See the section on the effect of style sheets on bidirectionality for more information.
修改块级别元素以及行内元素传统的展现机制,同时会对双向文本机制存在影响。请参看”样式表对双向文本的影响“部分获取更多信息。