link Setting Link Information

<link> Setting Link Information

You use the XHTML <link> element to indicate the relationship of other documents to the current one, such as specifying an external stylesheet. This element is empty and goes in the <head> section of a document. This element is supported in XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, and XHTML 1.1. Here are the attributes of <link> :

  • charset Specifies the character encoding of the linked document. Set this to an RFC 2045 language character set string; the default value is ISO-8859-1. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • class Gives the style class of the element. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • dir Sets the direction of text that doesn't have an inherent direction in which you should read it, called directionally neutral text. You can set this attribute to ltr , for left-to-right text, or rtl , for right-to-left text. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • href Contains the target URI of the resource. You must assign a value to either this attribute or the id attribute. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • hreflang Indicates the base language of the target indicated in the href attribute. Set this to RFC 1766 values. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • id Refers to the element; set this attribute to a unique identifier. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • lang Specifies the base language used in the element. Applies only when the document is interpreted as HTML. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • media Specifies the device that the document will be displayed on. Possible values are screen (the default), print , projection , braille , speech , or all (style information should be used for all devices). (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • rel Gives the relationship described by the hyperlink. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • rev Same as the rel attribute, but the syntax works in the reverse direction. For example, a link from A to B with rel="X" signifies the same relationship as a link from B to A with rev="X" . (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • style Inline style indicating how to render the element. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • target Indicates the named frame that serves as the target of the link. (XHTML 1.0 Transitional, XHTML 1.0 Frameset.)

  • title Contains the title of the element. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • type Indicates the MIME type of the target given in the href attribute. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

  • xml:lang Specifies the base language for the element when the document is interpreted as an XML document. (XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1.)

This element supports these event attributes: onclick , ondblclick , onmousedown , onmouseup , onmouseover , onmousemove , onmouseout , onkeypress , onkeydown , and onkeyup .

The <link> element specifies the relationship of the current document to other documents. I'll use this element to handle external stylesheets. You indicate the relationship with the rel attribute, which can take these values:

  • rel=alternate Links to an alternate resource

  • rel=appendix Links to an appendix

  • rel=bookmark Links to bookmarks, which provide links to entry points into a document

  • rel=chapter Links to a chapter

  • rel=contents Links to the contents section

  • rel=copyright Links to a copyright document for the current document

  • rel=glossary Links to a document providing a glossary of terms

  • rel=help Links to a document providing help

  • rel=home Links to a home page

  • rel=index Links to a document providing an index

  • rel= next Links to the next document

  • rel=previous Links to the previous document

  • rel=section Links to a section

  • rel=start Links to the start of a resource

  • rel=stylesheet Links to an external stylesheet

  • rel=subsection Links to a subsection

  • rel=toc Links to a document that holds a table of contents

  • rel=up Links to the parent of the current document.

Here's an example showing how to use an external stylesheet. I'm setting rel to stylesheet to indicate that the linked-to item is a stylesheet and href to the URI of the stylesheet:

Listing ch17_04.html
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">     <head>         <title>             Working With External Style Sheets         </title>  <link rel="stylesheet" href="ch17_05.css">  </head>     <body>        <center>            <h1>                Working With External Style Sheets            </h1>            <p>            This document is displayed using an external style sheet.            </p>        </center>     </body> </html> 

Here's the stylesheet I'm using, ch17_05.css:

Listing ch17_05.css
 body {background-color: #FFFFCC; font-family: Arial} a:link {color: #0000FF} a:visited {color: #FFFF00} a:hover {color: #00FF00} a:active {color: #FF0000} p {font-style: italic} 

That's all it takes. You can see the results in Figure 17-3. I'll take a closer look at working with stylesheets later in this chapter.

Figure 17-3. Using an external stylesheet in Netscape Navigator.

graphics/17fig03.gif



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net