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: optional

開始標籤:可選,結束標籤:可選

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.

文 檔的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元素。有關框架的更多信息請參閱本規範的相應部分。

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.

修改塊級別元素以及行內元素傳統的展現機制,同時會對雙向文本機制存在影響。請參看”樣式表對雙向文本的影響“部分獲取更多信息。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章