-
Notifications
You must be signed in to change notification settings - Fork 0
/
linksChpt7.htm
70 lines (70 loc) · 6.88 KB
/
linksChpt7.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Creating Links</title>
<link rel="stylesheet" href="_CSSChpt7/styles.css">
</head>
<body>
<header role="banner">
<h1>HTML Essential Training</h1>
<h2>Creating Links</h2>
<nav role="navigation">
<ul>
<li><a href="intro.htm" title="Introduction to HTML">Introduction to HTML</a></li>
<li><a href="syntax.htm" title="HTML syntax">HTML syntax</a></li>
<li><a href="structure.htm" title="Structuring pages">Structuring pages</a></li>
<li><a href="links.htm" title="Creating links">Creating links</a></li>
<li><a href="reference.htm" title="HTML Reference">HTML reference</a></li>
<li><a href="next.htm" title="Next steps">Next steps</a></li>
</ul>
</nav>
</header>
<main role="main">
<article role="article">
<header>
<p>Perhaps the most important aspect of HTML is the ability to link from one document to another. This is the basic concept underlying the web and without this functionality the World Wide Web would not exist. </p>
</header>
<section>
<h3>Link syntax</h3>
<p>Creating links is relatively straightforward, and the syntax provides a lot of flexibility in where and how links are applied. To create a link, you’ll use the anchor element (<a>) to wrap the content you wish to convert to a link. Attributes inside the anchor tag tell the browser where the page is linking to, or point to an external resource that the browser should download.<br>
Take the following link example:</p>
<pre><a href=”syntax.htm” title=”learn more about syntax”>HTML syntax</a></pre>
<p>Here the text “HTML syntax” would now appear as a clickable link. The <b>href</b> attribute tells the browser how to <em>resolve</em> the link; that is where the user should be directed when the link is clicked. The optional <b>title</b> attribute provides a description of the link and is helpful in making the link more accessible.</p>
</section>
<section>
<h3>Link types</h3>
<p>There are three basic types of link: <b>absolute</b>, <b>site-root relative</b>, and <b>document relative</b>. Each of these types refers to the value of the <b>href</b> attribute, which directs how the browser should resolve a link once the link has been clicked. </p>
<h4>Absolute links </h4>
<p>These links contain the entire URL necessary to resolve a link, including the protocol. This is usually done for external links, which are links to pages outside of the current site. Here’s an example of an absolute link:</p>
<pre><a href=”http://www.lynda.com” title=”You can learn it at lynda.com!”>lynda.com</a></pre>
<h4>Document relative links </h4>
<p>These links are commonly used to navigate internally within a site. For example, if you were on the home page of your site, and wanted to navigate to the contact page, you simply provide the path from the home page to the contact page for the <b>href</b> value. Doing this requires you to understand the directory structure of your site, and when you need to navigate into, or out of, folders. Take the following example:</p>
<pre><a href=”contact.htm” title=”our contact page”>Contact us</a></pre>
<p>This link assumes that the contact page and the current page are in the same directory. If the contact page were located in a directory below the current page, the link would look like this:</p>
<pre><a href=”resources/contact.htm” title=”our contact page”>Contact us</a></pre>
<p>This assumes the contact page is in a directory titled “resources” and is one level below the current page. To move <b>out</b> of a directory, you precede the page with the “../” characters. In this case of our contact link it would look like this:</p>
<pre><a href=”../contact.htm” title=”our contact page”>Contact us</a></pre>
<p> This link would move up from the current directory and find the contact.htm page in the parent directory. You can use as many of these “../” as you need to move up and properly resolve the link.</p>
<h4>Site-Root Relative Links</h4>
<p> These are similar to document relative links, but start at the root folder for the site and then move down through directories to the desired page. Unlike document relative links, which depend on the current location of the page to properly resolve links, site-root relative links are written the same no matter the current location within your site. All links are preceded by a forward slash (/) that refers to the root directory. Here’s an example:</p>
<pre><a href=”/contact.htm” title=”our contact page”>Contact us</a></pre>
<p> In this example, the link is resolved by going directly into the site’s root folder and finding the contact page. If the contact page were located deeper within the site, the link would look like this:</p>
<pre><a href=”/resources/contact.htm” title=”our contact page”>Contact us</a></pre>
</section>
<section>
<h3>Fragment identifiers </h3>
<p>Occasionally you’ll want a link to refer to a specific location within a page. This can be done using a special kind of link called a fragment identifier. These links point to elements with a specific <b>ID</b> attribute. Let’s say, for example, you have a long list of <b>FAQs</b> on a page organized by categories and you had a heading at the top of each category. If you assigned each heading an ID attribute, you could use those IDs to create a links that jump to specific categories. For example, you could format the Camping FAQs heading like this:</p>
<pre><h2 id=”camp”>Camping</h2></pre>
<p> Elsewhere on the page you could link to this section by creating the following link:</p>
<pre><a href=”#camp”>Learn more about camping</a></pre>
<p> Note the hash symbol (#) prior to the ID value. This tells the browser to look for an element with the ID value that follows.You can link to fragment identifiers on external pages as well. Simply append the fragment identifier to the URL and the link will jump to not only to that page, but that specific section as well.</p>
<pre><a href=”faq.htm#camp”>Read our FAQ on camping.</a></pre>
</section>
</article>
</main>
<footer role="contentinfo">
<p>© <a href="http://www.lynda.com" title="lynda.com" target="_blank">lynda.com</a> | follow me and lynda.com on Twitter! <a href="https://twitter.com/jameswillweb" title="Follow me on Twitter">@jameswillweb</a> <a href="https://twitter.com/lynda" title="Follow lynda.com on Twitter">@lynda</a></p>
</footer>
</body>
</html>