Lecture notes - Links

Adding a link tag follows the standard format that you learned about adding attributes in the last project:
<tag attribute="value">content for element</tag>
Review:

Examples of tags with added attributes:

<p align="right">This is a paragraph of text for demonstration.</p>
<h1 align="center">This is a sample heading that could be on a web page.</h1>
<ul type="square"><li>This is a bulleted item</li></ul>
<a href="filename or URL">text for link</a>

<p>
Please visit my new <a href="mywebpage.html">web page</a>.
</p>

The above code represents a paragraph on a web page that will display this sentence in the browser:

Please visit my new web page.

The words "web page" are surrounded by code to make the words appear as a link. In the browser they will appear blue and underlined to indicate they represent the link. When the user clicks on the link text, it will open a page named mywebpage.html. Look carefully at the code to see how it was created.


Relative links

If pages are stored in the same location on the same server, link code is written as a "relative" link.

More examples of relative links when pages are all stored in the same location:

Suppose I have a three page website.
The first page is the home page named default.html.
The second page is a biography page of my family named family.html.
The third page is a picture page of my family named familyphoto.html.

The link to my home page would look like:

<p>
Visit my <a href="default.html">Home Page</a>.
</p>

The link to the second page would be:

<h2>
Go to <a href="family.html">biographical information</a> for the Whobrey family.
</h2>

The link to the third page would be:

<h3>
See our <a href="familyphoto.html">photos of the Whobrey Bunch</a>.
</h3>

Note:

These links also are a good example of proper "nesting order" for codes. Notice that the complete code for the link is contained inside the code for the paragraph or heading. The first element starts, the link starts and ends, the first element ends. The code for the link is nested inside the paragraph or heading code. When codes are nested, they are written in this order:

Proper nesting order is important when coding following XHTML rules. Remember the format for nested elements:
<first element><second element>text content</second element></first element>

Examples:
<p><a href="http://www.google.com">Google</a></p>
<p>The strong and emphasis tags can be used to make text <strong><em>bold and italic</em></strong></p>.

Hint:
For code to be considered "valid," you cannot put paragraphs INSIDE headings and you cannot put headings INSIDE paragraphs. These are separate elements. Text can be a paragraph or it can be a heading but it cannot be both at the same time.

Examples of invalid elements.

<h3><p>Text content</p></h3>
<p><h3>Text content</h3></p>

Examples of valid elements.

<p>Text content</p>
<h3>Text content.</h3>


Absolute links

If a link is to a page OUTSIDE of your own website, the value for the href attribute must include the complete URL.

<p>
For more information about attending one of the best community colleges in the nation, visit the home page for <a href="http://www.parkland.edu/">Parkland College</a> in Champaign, Illinois.
</p>

More examples:

<p>Go to <a href="http://www.google.com">Google.</a></p>
<p>Visit <a href="http://www.geocities.com">Geocities.</a></p>


For more information about the anchor tag, visit:
http://www.w3schools.com/html/html_links.asp

W3Schools is an excellent online resource for learning more about HTML/XHTML coding. Go to W3Schools and explore the pages for HTML and XHTML that apply to the elements in this project. Check out the links to "examples" of code at this website. These pages give you an opportunity to type in code and try it out to see if it works!! Practicing with HTML/XHTML code is the only way to really understand how it works!


Hosted by www.Geocities.ws

1