Cari di HTML5 
    HTML 5
Daftar Isi
(Sebelumnya) 4.12. Links5. Loading Web pages (Berikutnya)

4.13. Common idioms without dedicated elements

4.13.1 The main part of the content

The main content of a page — not including headers and footers, navigation links, sidebars, advertisements, and so forth — can be marked up in a variety of ways, depending on the needs of the author.

The simplest solution is to not mark up the main content at all, and just leave it as implicit. Another way to think of this is that the body elements marks up the main content of the page, and the bits that aren't main content are excluded through the use of more appropriate elements like aside and nav.

Here is a short Web page marked up along this minimalistic school of thought. The main content is highlighted. Notice how all the other content in the body is marked up with elements to indicate that it's not part of the main content, in this case header, nav, and footer.

<!DOCTYPE HTML><html> <head>  <title> My Toys </title> </head> <body>  <header>   <h1>My toys</h1>  </header>  <nav>   <p><a href="/">Home</a></p>   <p><a href="/contact">Contact</a></p>  </nav>  <p>I really like my chained book and my telephone. I'm not such a  fan of my big ball.</p>  <p>Another toy I like is my mirror.</p>  <footer>   <p>© copyright 2010 by the boy</p>  </footer> </body></html>

If the main content is an independent unit of content that one could imagine syndicating independently, then the article element would be appropriate to mark up the main content of the document.

The document in the previous example is here recast as a blog post:

<!DOCTYPE HTML><html> <head>  <title> The Boy Blog: My Toys </title> </head> <body>  <header>   <h1>The Boy Blog</h1>  </header>  <nav>   <p><a href="/">Home</a></p>   <p><a href="/contact">Contact</a></p>  </nav>  <article>   <header> <h1>My toys</h1> <p>Published August 4th</p>   </header>   <p>I really like my chained book and my telephone. I'm not such a   fan of my big ball.</p>   <p>Another toy I like is my mirror.</p>  </article>  <footer>   <p>© copyright 2010 by the boy</p>  </footer> </body></html>

If the main content is not an independent unit of content so much as a section of a larger work, for instance a chapter, then the section element would be appropriate to mark up the main content of the document.

Here is the same document, case as a chapter in an online book:

<!DOCTYPE HTML><html> <head>  <title> Chapter 2: My Toys — The Book of the Boy </title> </head> <body>  <header>   <h1>Chapter 2: My Toys</h1>  </header>  <nav>   <p><a href="/">Front Page</a></p>   <p><a href="/toc">Daftar Isi</a></p>   <p><a href="/c1">Chapter 1</a> — <a href="/c3">Chapter 3</a></p>  </nav>  <section>   <p>I really like my chained book and my telephone. I'm not such a   fan of my big ball.</p>   <p>Another toy I like is my mirror.</p>  </section>  <footer>   <p>© copyright 2010 by the boy</p>  </footer> </body></html>

If neither article nor section would be appropriate, but the main content still needs an explicit element, for example for styling purposes, then the div element can be used.

This is the same as the original example, but using div for the main content instead of leaving it implied:

<!DOCTYPE HTML><html> <head>  <title> My Toys </title>  <style>   body > div { background: navy; color: yellow; }  </style> </head> <body>  <header>   <h1>My toys</h1>  </header>  <nav>   <p><a href="/">Home</a></p>   <p><a href="/contact">Contact</a></p>  </nav>  <div>   <p>I really like my chained book and my telephone. I'm not such a   fan of my big ball.</p>   <p>Another toy I like is my mirror.</p>  </div>  <footer>   <p>© copyright 2010 by the boy</p>  </footer> </body></html>

4.13.2 Bread crumb navigation

This specification does not provide a machine-readable way of describing bread-crumb navigation menus. Authors are encouraged to just use a series of links in a paragraph. The nav element can be used to mark the section containing these paragraphs as being navigation blocks.

In the following example, the current page can be reached via two paths.

<nav> <p>  <a href="/">Main</a> >  <a href="/products/">Products</a> >  <a href="/products/dishwashers/">Dishwashers</a> >  <a>Second hand</a> </p> <p>  <a href="/">Main</a> >  <a href="/second-hand/">Second hand</a> >  <a>Dishwashers</a> </p></nav>

4.13.3 Tag clouds

This specification does not define any markup specifically for marking up lists of keywords that apply to a group of pages (also known as tag clouds). In general, authors are encouraged to either mark up such lists using ul elements with explicit inline counts that are then hidden and turned into a presentational effect using a style sheet, or to use SVG.

Here, three tags are included in a short tag cloud:

<style>@media screen, print, handheld, tv {  /* should be ignored by non-visual browsers */  .tag-cloud > li > span { display: none; }  .tag-cloud > li { display: inline; }  .tag-cloud-1 { font-size: 0.7em; }  .tag-cloud-2 { font-size: 0.9em; }  .tag-cloud-3 { font-size: 1.1em; }  .tag-cloud-4 { font-size: 1.3em; }  .tag-cloud-5 { font-size: 1.5em; }}</style>...<ul class="tag-cloud"> <li class="tag-cloud-4"><a title="28 instances" href="/t/apple">apple</a> <span>(popular)</span> <li class="tag-cloud-2"><a title="6 instances"  href="/t/kiwi">kiwi</a> <span>(rare)</span> <li class="tag-cloud-5"><a title="41 instances" href="/t/pear">pear</a> <span>(very popular)</span></ul>

The actual frequency of each tag is given using the title attribute. A CSS style sheet is provided to convert the markup into a cloud of differently-sized words, but for user agents that do not support CSS or are not visual, the markup contains annotations like "(popular)" or "(rare)" to categorize the various tags by frequency, thus enabling all users to benefit from the information.

The ul element is used (rather than ol) because the order is not particularly important: while the list is in fact ordered alphabetically, it would convey the same information if ordered by, say, the length of the tag.

The tag rel-keyword is not used on these a elements because they do not represent tags that apply to the page itself; they are just part of an index listing the tags themselves.

4.13.4 Conversations

This specification does not define a specific element for marking up conversations, meeting minutes, chat transcripts, dialogues in screenplays, instant message logs, and other situations where different players take turns in discourse.

Instead, authors are encouraged to mark up conversations using p elements and punctuation. Authors who need to mark the speaker for styling purposes are encouraged to use span or b. Paragraphs with their text wrapped in the i element can be used for marking up stage directions.

This example demonstrates this using an extract from Abbot and Costello's famous sketch, Who's on first:

<p> Costello: Look, you gotta first baseman?<p> Abbott: Certainly.<p> Costello: Who's playing first?<p> Abbott: That's right.<p> Costello becomes exasperated.<p> Costello: When you pay off the first baseman every month, who gets the money?<p> Abbott: Every dollar of it.

HTML does not have a good way to mark up graphs, so descriptions of interactive conversations from games are more difficult to mark up. This example shows one possible convention using dl elements to list the possible responses at each point in the conversation. Another option to consider is describing the conversation in the form of a DOT file, and outputting the result as an SVG image to place in the document. [DOT]

<p> Next, you meet a fisherman. You can say one of several greetings:<dl> <dt> "Hello there!" <dd>  <p> He responds with "Hello, how may I help you?"; you can respond with:  <dl>   <dt> "I would like to buy a fish."   <dd> <p> He sells you a fish and the conversation finishes.   <dt> "Can I borrow your boat?"   <dd> <p> He is surprised and asks "What are you offering in return?". <dl> <dt> "Five gold." (if you have enough) <dt> "Ten gold." (if you have enough) <dt> "Fifteen gold." (if you have enough) <dd> <p> He lends you his boat. The conversation ends. <dt> "A fish." (if you have one) <dt> "A newspaper." (if you have one) <dt> "A pebble." (if you have one) <dd> <p> "No thanks", he replies. Your conversation options at this point are the same as they were after asking to borrow his boat, minus any options you've suggested before. </dl>   </dd>  </dl> </dd> <dt> "Vote for me in the next election!" <dd> <p> He turns away. The conversation finishes. <dt> "Sir, are you aware that your fish are running away?" <dd>  <p> He looks at you skeptically and says "Fish cannot run, sir".  <dl>   <dt> "You got me!"   <dd> <p> The fisherman sighs and the conversation ends.   <dt> "Only kidding."   <dd> <p> "Good one!" he retorts. Your conversation options at this   point are the same as those following "Hello there!" above.   <dt> "Oh, then what are they doing?"   <dd> <p> He looks at his fish, giving you an opportunity to steal   his boat, which you do. The conversation ends.  </dl> </dd></ul>

In some games, conversations are simpler: each character merely has a fixed set of lines that they say. In this example, a game FAQ/walkthrough lists some of the known possible responses for each character:

<section> <h1>Dialogue</h1> <p><small>Some characters repeat their lines in order each time you interact with them, others randomly pick from amongst their lines. Those who respond in order have numbered entries in the lists below.</small> <h2>The Shopkeeper</h2> <ul>  <li>How may I help you?  <li>Fresh apples!  <li>A loaf of bread for madam? </ul> <h2>The pilot</h2> <p>Before the accident: <ul>  </li>I'm about to fly out, sorry!  </li>Sorry, I'm just waiting for flight clearance and then I'll be off! </ul> <p>After the accident: <ol>  <li>I'm about to fly out, sorry!  <li>Ok, I'm not leaving right now, my plane is being cleaned.  <li>Ok, it's not being cleaned, it needs a minor repair first.  <li>Ok, ok, stop bothering me! Truth is, I had a crash. </ol> <h2>Clan Leader</h2> <p>During the first clan meeting: <ul>  <li>Hey, have you seen my daughter? I bet she's up to something nefarious again...  <li>Nice weather we're having today, eh?  <li>The name is Bailey, Jeff Bailey. How can I help you today?  <li>A glass of water? Fresh from the well! </ul> <p>After the earthquake: <ol>  <li>Everyone is safe in the shelter, we just have to put out the fire!  <li>I'll go and tell the fire brigade, you keep hosing it down! </ol></section>

4.13.5 Footnotes

HTML does not have a dedicated mechanism for marking up footnotes. Here are the suggested alternatives.


For annotations, the a element should be used, pointing to an element later in the document. The convention is that the contents of the link be a number in square brackets.

In this example, a footnote in the dialogue links to a paragraph below the dialogue. The paragraph then reciprocally links back to the dialogue, allowing the user to return to the location of the footnote.

<p> Announcer: Number 16: The <i>hand</i>.<p> Interviewer: Good evening. I have with me in the studio tonightMr Norman St John Polevaulter, who for the past few years has beencontradicting people. Mr Polevaulter, why <em>do</em> youcontradict people?<p> Norman: I don't. <sup><a href="_html5.php?_html=37#fn1" id="r1">[1]</a></sup><p> Interviewer: You told me you did!...<section> <p id="fn1"><a href="#r1">[1]</a> This is, naturally, a lie, but paradoxically if it were true he could not say so without contradicting the interviewer and thus making it false.</p></section>

For side notes, longer annotations that apply to entire sections of the text rather than just specific words or sentences, the aside element should be used.

In this example, a sidebar is given after a dialogue, giving it some context.

<p> <span class="speaker">Customer</span>: I will not buy this record, it is scratched.<p> <span class="speaker">Shopkeeper</span>: I'm sorry?<p> <span class="speaker">Customer</span>: I will not buy this record, it is scratched.<p> <span class="speaker">Shopkeeper</span>: No no no, this's'a tobacconist's.<aside> <p>In 1970, the British Empire lay in ruins, and foreign nationalists frequented the streets — many of them Hungarians (not the streets — the foreign nationals). Sadly, Alexander Yalt has been publishing incompetently-written phrase books.</aside>

For figures or tables, footnotes can be included in the relevant figcaption or caption element, or in surrounding prose.

In this example, a table has cells with footnotes that are given in prose. A figure element is used to give a single legend to the combination of the table and its footnotes.

<figure> <figcaption>Table 1. Alternative activities for knights.</figcaption> <table>  <tr>   <th> Activity   <th> Location   <th> Cost  <tr>   <td> Dance   <td> Wherever possible   <td> £0<sup><a href="_html5.php?_html=37#fn1">1</a></sup>  <tr>   <td> Routines, chorus scenes<sup><a href="_html5.php?_html=37#fn2">2</a></sup>   <td> Undisclosed   <td> Undisclosed  <tr>   <td> Dining<sup><a href="_html5.php?_html=37#fn3">3</a></sup>   <td> Camelot   <td> Cost of ham, jam, and spam<sup><a href="_html5.php?_html=37#fn4">4</a></sup> </table> <p id="fn1">1. Assumed.</p> <p id="fn2">2. Footwork impeccable.</p> <p id="fn3">3. Quality described as "well".</p> <p id="fn4">4. A lot.</p></figure>

4.14 Disabled elements

An element is said to be actually disabled if it falls into one of the following categories:

This definition is used to determine what elements can be focused and which elements match the :disabled pseudo-class.

4.15 Matching HTML elements using selectors

4.15.1 Case-sensitivity

The Selectors specification leaves the case-sensitivity of IDs, classes, element names, attribute names, and attribute values to be defined by the host language. [SELECTORS]

The unique identifier of HTML elements in documents that are in quirks mode must be treated as ASCII case-insensitive for the purposes of selector matching.

Classes from the class attribute of HTML elements in documents that are in quirks mode must be treated as ASCII case-insensitive for the purposes of selector matching.

Attribute and element names of HTML elements in HTML documents must be treated as ASCII case-insensitive for the purposes of selector matching.

Everything else (attribute values on HTML elements, IDs and classes in no-quirks mode and limited-quirks mode, and element names, attribute names, and attribute values in XML documents) must be treated as case-sensitive for the purposes of selector matching.

4.15.2 Pseudo-classes

There are a number of dynamic selectors that can be used with HTML. This section defines when these selectors match HTML elements. [SELECTORS] [CSSUI]

:link
:visited

All a elements that have an href attribute, all area elements that have an href attribute, and all link elements that have an href attribute, must match one of :link and :visited.

Other specifications might apply more specific rules regarding how these elements are to match these pseudo-classes, to mitigate some privacy concerns that apply with straightforward implementations of this requirement.

:active

The :active pseudo-class is defined to match an element while an element is being activated by the user. For the purposes of defining the :active pseudo-class only, an HTML user agent must consider an element as being activated if it is:

  • An element falling into one of the following categories between the time the user begins to indicate an intent to trigger the element's activation behavior and either the time the user stops indicating an intent to trigger the element's activation behavior, or the time the element's activation behavior has finished running, which ever comes first:

    For example, if the user is using a keyboard to push a button element by pressing the space bar, the element would match this pseudo-class in between the time that the element received the keydown event and the time the element received the keyup event.

  • An element that the user indicates using a pointing device while that pointing device is in the "down" state (e.g. for a mouse, between the time the mouse button is pressed and the time it is depressed).

  • An element that has a descendant that is currently matching the :active pseudo-class.

:hover

The :hover pseudo-class is defined to match an element while the user designates an element with a pointing device. For the purposes of defining the :hover pseudo-class only, an HTML user agent must consider an element as being one that the user designates if it is:

  • An element that the user indicates using a pointing device.

  • An element that has a descendant that the user indicates using a pointing device.

  • An element that is the labeled control of a label element that is currently matching :hover.

Consider in particular a fragment such as:

<p> <label for=c> <input id=a> </label> <span id=b> <input id=c> </span> </p>

If the user designates the element with ID "a" with their pointing device, then the p element (and all its ancestors not shown in the snippet above), the label element, the element with ID "a", and the element with ID "c" will match the :hover pseudo-class. The element with ID "a" matches it from condition 1, the label and p elements match it because of condition 2 (one of their descendants is designated), and the element with ID "c" matches it through condition 3 (its label element matches :hover). However, the element with ID "b" does not match :hover: its descendant is not designated, even though it matches :hover.

:enabled

The :enabled pseudo-class must match any element falling into one of the following categories:

:disabled

The :disabled pseudo-class must match any element that is actually disabled.

:checked

The :checked pseudo-class must match any element falling into one of the following categories:

:indeterminate

The :indeterminate pseudo-class must match any element falling into one of the following categories:

:default

The :default pseudo-class must match any element falling into one of the following categories:

:valid

The :valid pseudo-class must match any element falling into one of the following categories:

:invalid

The :invalid pseudo-class must match any element falling into one of the following categories:

:in-range

The :in-range pseudo-class must match all elements that are candidates for constraint validation, have range limitations, and that are neither suffering from an underflow nor suffering from an overflow.

:out-of-range

The :out-of-range pseudo-class must match all elements that are candidates for constraint validation, have range limitations, and that are either suffering from an underflow or suffering from an overflow.

:required

The :required pseudo-class must match any element falling into one of the following categories:

:optional

The :optional pseudo-class must match any element falling into one of the following categories:

:read-only
:read-write

The :read-write pseudo-class must match any element falling into one of the following categories, which for the purposes of Selectors are thus considered user-alterable: [SELECTORS]

The :read-only pseudo-class must match all other HTML elements.

:dir(ltr)

The :dir(ltr) pseudo-class must match all elements whose directionality is 'ltr'.

:dir(rtl)

The :dir(rtl) pseudo-class must match all elements whose directionality is 'rtl'.

Another section of this specification defines the target element used with the :target pseudo-class.

This specification does not define when an element matches the :focus or :lang() dynamic pseudo-classes, as those are all defined in sufficient detail in a language-agnostic fashion in the Selectors specification. [SELECTORS]

Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved.
(Sebelumnya) 4.12. Links5. Loading Web pages (Berikutnya)