HTML4.01规范-HTML文档的顶层结构(3)

7.5 The document body

7.5.1 The BODY element

<!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: optionalcss

开始标签:可选,结束标签:可选
html

Attribute definitions数据库

属性定义
编程

background = uri [CT]
Deprecated. The value of this attribute is a URI that designates an p_w_picpath resource. The p_w_picpath generally tiles the background (for visual browsers)
不推荐。该属性的值是一个指向一个图片资源的URI。对于可视化浏览器来讲,图片一般平铺成背景。
text = color [CI]
Deprecated. This attribute sets the foreground color for text (for visual browsers)
不推荐。对于可视化浏览器,该属性设置文本的前景颜色。
link = color [CI]
Deprecated. This attribute sets the color of text marking unvisited hypertext links (for visual browsers)
不推荐。对于可视化浏览器,该属性设置未被访问的超连接文本的颜色。
vlink = color [CI]
Deprecated. This attribute sets the color of text marking visited hypertext links (for visual browsers)
不推荐。对于可视化浏览器,该属性设置被访问过的超连接文本的颜色。.
alink = color [CI]
Deprecated. This attribute sets the color of text marking hypertext links when selected by the user (for visual browsers)
不推荐。对于可视化浏览器,该属性设置用户选中超连接时文本的颜色。

 

 

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, p_w_picpaths, 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.app

文 档的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.编程语言

不推荐的示例:ide

下面的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元素。有关框架的更多信息请参阅本规范的相应部分。

7.5.2 Element identifiers: the id and class attributes

Attribute definitions

属性定义

id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document
该属性命名一个元素。在文档内这个名字必须惟一。
class = cdata-list [CS]
This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters
该属性将一个或一组class名字赋予一个元素。不一样的元素能够拥有相同的class名字。多个class名字之间必须以空白字符分隔。
The id attribute assigns a unique identifier to an element (which may be verified by an SGML parser). For example, the following paragraphs are distinguished by their id values:
id属性为元素赋予一个惟一的标识符,该标识符可能被SGML解析器验证。例如,下面的两个段落的id值各自标识了它们自身:
<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:

  • As a style sheet selector.
  • As a target anchor for hypertext links.
  • As a means to reference a particular element from a script.
  • As the name of a declared OBJECT element.
  • For general purpose processing by user agents (e.g. for identifying fields when extracting data from HTML pages into a database, translating HTML documents into other formats, etc.).

在HTML中id属性拥有多个角色,具体以下:

  • 做为样式表的选择器
  • 做为超连接的目标锚定点
  • 做为在script脚本中引用指定元素的方法
  • 做为一个已声明的OBJECT元素的名字
  • 被用户代理用于通常目的的处理(例如,当从HTML页面中向数据库中抽取数据时,标识字段,将HTML文档转换成其余格式,等等)

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:

  • As a style sheet selector (when an author wishes to assign style information to a set of elements).
  • For general purpose processing by user agents.

在另外一方面,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&eacute;clar&eacute;e deux fois</SPAN>
<P><SPAN id="msg2" class="warning" lang="fr">Variable ind&eacute;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锚定部分“以获取更多信息。

7.5.3 Block-level and inline elements

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元素中有一部分被称为块级别元素,另外一部分称为行内元素(也叫作文本级别元素)。他们的区别表如今以下方面:

Content model
Generally, block-level elements may contain inline elements and other block-level elements. Generally, inline elements may contain only data and other inline elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements.
Formatting
By default, block-level elements are formatted differently than inline elements. Generally, block-level elements begin on new lines, inline elements do not. For information about white space, line breaks, and block formatting, please consult the section on text.
Directionality
For technical reasons involving the [UNICODE] bidirectional text algorithm, block-level and inline elements differ in how they inherit directionality information. For details, see the section on inheritance of text direction.
内容模型
通常来讲,块级别元素能够承载行内元素以及其余块级别元素。行内元素通常只能承载数据和其余行内元素。 能够看出,在结构方面它们的区别是,块元素建立比行内元素更大的结构。elements.

格式化
缺省状况下,块级别元素会采用与行内元素不一样的格式化方式。通常来讲,块级别元素以新行开始,而行内元素不会。想要获取有关空白空间,折行以及块格式化的信息,请参阅”文本“部分。

方向性
因为与[UNICDOE]双向文本机制相关的技术性缘由,块级别和行内元素在如何继承方向信息的机制上是不一样。请参见"文本方向的继承"部分以获取更多细节信息。

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.

修改块级别元素以及行内元素传统的展示机制,同时会对双向文本机制存在影响。请参看”样式表对双向文本的影响“部分获取更多信息。
相关文章
相关标签/搜索