mohammed mohsen 2011. links links are what make the world wide web web-like one document on the web...

19
HTML Part2 Mohammed Mohsen 2011

Upload: madeleine-garrison

Post on 28-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

HTML Part2

Mohammed Mohsen 2011

Page 2: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Head lines:

Spanning

Divisions

Links

Page 3: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Spanning Spanning tags (<span>) are used to span inline styles across multiple characters or words. In effect, the <span> tag allows you to define your own inline styles. For example, if you need to specify text that is bold, red, and underlined, you could use code similar to the following:

<style>

.emphasis { color:red; text-decoration:underline; font-weight:bold; }

</style>

<p><span class="emphasis">This text is emphasized</span>,

while this text is not.</p>

The <span> tag allows you to apply the stylistic formatting inline, exactly where you want it.

Page 4: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

DivisionsDivisions are a higher level of block formatting, usually reserved for groups of related paragraphs, entire pages, or sometimes only a single paragraph. The division tag (<div>) provides a simple solution for formatting larger sections of a document. For example, if you need a particular section of a document outlined with a border, you can define an appropriate style and delimit that part of the document with <div> tags, as in the following example:<style>

.bordered{border-style:solid;}

</style>

<p>This is a normal paragraph.</p>

<div class="bordered"><p>This is a paragraph delimited with

The defined div style which includes a border.</p></div>

Page 5: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Links

Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those in turn to other documents, and so forth. The resulting structure, if diagramed, resembles a web. The comparison has spawned many "web" terms commonly used on the Internet—electronic robots that scour the Web are known as "spiders," and so on.Besides linking to other documents, you can link to just about any content that can be delivered over the Internet—media files, e-mail addresses, FTP sites, and so on.

Page 6: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

What's in a Link?Web links have two basic components, the link and the target.The link is the text in the main document that refers to another document.The target is the document (or particular location in the document) to which the link leads.

Page 7: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

DNS(The Domain Name System )Although programs theoretically could refer to hosts,

mailboxes, and other resources by their network (e.g., IP) addresses, these addresses are hard for people to remember. Also, sending e-mail to [email protected] means that if Ali's ISP or organization moves the mail server to a different machine with a different IP address, her e-mail address has to change.

Page 8: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

As mentioned in the introduction to this chapter, you can link

to other things besides HTTP documents. All you need is the

URL (Uniform Resource Locator, previously Universal

Resource Locator)of the item you wish to link to, and the

protocol necessary to reach the item.

http://www.m-mohsen.com/web/index.html

This URL consists of three parts: the protocol (http), the DNS

name of the host (www.m-mohsen.com), and the file name

(web/index_n.html), with certain punctuation separating the

pieces. The file name is a path relative to the default Web

directory at m-mohsen.com.

Page 9: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

For example, if you wanted to link to a document on an FTP site, you could use an anchor tag similar to the following:

<a href="ftp://ftp.example.com/pub/example.zip">Zipped copy of the files</a>

Note that the protocol is specified (ftp: instead of http:), and the server name is specified (ftp.example.com), as is the path and filename (/pub and example .zip). A similar method can be used to link to an e-mail address (href="mailto:[email protected]"). Clicking such a link will generally spawn the user's e-mail client ready to send an e-mail to the address specified.

Page 10: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Linking to a Web PageThe most popular link style on the Web is a link to another Web page or document. Such a link, when activated, causes the target page to load in the client browser. Control is then transferred to the target page—its scripts run, and so on.To link to another page on the Internet, you simply specify the target's URL in the anchor tag. Suppose you want to link to the products page of the Acme Web site and the page is named products.html and resides in the products directory on the Acme Web server. The href parameter of the link would be as follows: http://www.example.com/products/products.htmlNote that the URL (http://acme.example.com) contains the protocol, the server name, the directory name, and the filename. Figure 7-2 shows a breakdown of the various pieces of the URL.

Page 11: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

In the case of this URL, the various pieces are separated by various key characters:The protocol is first, and ends with a colon (http:).The server name is next, prefaced with a double slash (//

www.example.com).The directory (or directories) is next, separated with slashes

(/products/).The filename of the page is last, separated from the directory by a

slash(products.html ).

Page 12: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Absolute versus Relative LinksThere are two types of URL styles, and therefore two link types, that you need to understand: absolute and relative. You have seen absolute links, where the URL used in the link provides the full path, including the protocol and full server address. These links are called absolute links because the URL itself is absolute that is, it does not change no matter where the document in which it appears is kept.The other type of link, a relative link, does not provide all of the details to the referenced page; hence, its address is treated as relative to the document where the link appears. Relative links are only useful for linking to other pages on the same Web site, because any reference off of the same site requires the remote server's name.It's easier to understand the difference between the two types of links with an example. Suppose you are the Webmaster of example.com. You have several pages on the site, including the home page, a main products page, and hardware and software products pages. The home page is in the root directory of the server, while the product pages (all three) are in a products directory. The relative links back and forth between the pages are shown in Figures 7-3 and 7-4.

Page 13: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Note: that you can use directory shortcuts to specify where the pages are:Starting a directory with a slash (/) references it as a subdirectory of the root

directory.Starting a directory with a period and a slash (./ ) references it as a subdirectory

of the current directory (the directory where the current page resides).Starting a directory with a double period and a slash (.. / ) references it as a

parent directory to the current directory.

Page 14: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Relative links are easier to maintain on sections of Web sites where the pages in that section never change relationships to one another. For example, in the case of the site shown in Figures 7-3 and 7-4, if the products pages move as a whole unit to another place on the site, the relative links between the product pages won't change. If the links were coded as absolute (for example, http://www.example.com/ products/hardware.html), they would have to change.

Link TargetsNormally, links open the page they refer to in the active browser window, replacing the page currently displayed. However, you can control where the page opens using the target attribute in the link tag.

Page 15: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those
Page 16: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Link TitlesYou can also title a link, using the title attribute in the anchor tag. This causes most current browsers to display the text of the title as a ToolTip when the mouse hovers over them. For example, the following link will cause Internet Explorer 6 to display "Example.com's Web Site,"

Keyboard shortcutsEach link can be assigned a shortcut key for easy keyboard-only access using the accesskey attribute with the anchor tab. The accesskey attribute takes one letter as its value, the letter that can be used to access the link. For example, the following link defines "C" as the access key:<a href="http://www.example.com" accesskey="C">Table of <b>C</b>ontents</a>

Tab orderIt will also help your users if you define a tab order for the links in your document. As with most graphical operating systems, the tab key can be used to move through elements of the interface, including links. <a href=http://www.example.com tabindex="1">first link</a>

Page 17: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Creating an AnchorAnchor tags have another use; they can be used as a marker in the current document to provide a bookmark that can be directly linked to. For example, a large document might have several sections. You can place links at the top of the document (or in a special navigation frame) to each section, allowing the user to easily access each section.To create an anchor in a document, you use the anchor tag with the name attribute. For example, the following code creates a chapter01 anchor at the "Chapter 1" heading: <h1><a name="chapter1">Chapter 1</a></h1>To link to the anchor you use a standard link, but add the anchor name to the end of the URL in the link. To identify the name as an anchor, you separate it from the rest of the URL with a pound sign (#). For example, suppose the Chapter 1 anchor appears in the document book.html. To link to the Chapter 1 anchor, you could use the following code: <a href="http://www.example.com/book.html#chapter1">Go to Chapter 1</a> 

Page 18: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Note Because the URL in the link tag can contain the server and document names as well as the anchor name, you can link to anchors in the same document or any accessible document. If you are linking to an anchor in the same document, you can use a shortcut form of the URL, using only the pound sign and the anchor name as the URL.In addition to using the anchor tag for bookmarks, you can link to a block element's id attribute. For example, if Chapter 1 appears inside an <h1> tag, you can set the <h1> tag's id attribute to Chapter1 and omit the anchor link altogether, as shown in the following code example: <h1 id="chapter1">Chapter 1</h1>

Page 19: Mohammed Mohsen 2011. Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those

Thank You