Docsity

Creating Web Pages with XHTML: Structuring Content and Adding Images, Assignments of Computer Science

Toggle sidebar
bg1
Creating Web Pages with XHTML
Introduction
The HyperText Markup Language (HTML) is a language comprised of a series of coded tags that describe
the structure of a document. The idea is that most documents have common elements, such as titles,
paragraphs, etc. Because HTML is a markup language, you begin with the text of your page and add special
tags around words and paragraphs. These tags indicate different parts of a page and produce different
effects in the Web browser. HTML tags are the codes inside brackets (< >) that indicate the features of the
page. A text editor can be used to create and edit HTML documents. You can see the HTML code of any
Web page by choosing View > Source from the browser's menu bar.
HTML tags are not case sensitive, although the newest version of HTML, called XHTML (Extensible
Hypertext Markup Language), requires all tags to be written in lowercase. XHTML was designed to
improve and standardize HTML. With all that is being put on the Web it will take a long time before most
of the HTML on the Web is standardized. Although we will not be running our HTML as strict XHTML,
we will start using the standards. Most HTML tags require a corresponding closing tag. The closing tags
contain a backslash after the opening bracket. XHTML requires the backslash in the opening tag if a
closing tag is not required. The tags can be on the same line with the text or on a line by themselves. When
the Enter key is used in the text processor to move to the next line, a new-line character is created which is
ignored by HTML. Since extra spaces and blank lines are ignored in HTML, use them to line up the
opening and closing tags and to make your code easy to read so you can find errors. HTML does not
produce error messages, as programming languages do.
Many of the HTML tags can contain attributes. The attributes are listed inside the brackets with their
values, <TagName Attribute=”Value”>. According to the XHTML standards, attribute values should be
enclosed in quotes. The corresponding closing tag must not contain attributes. Each HTML tag has a
default interpretation in terms of its display properties, which may slightly differ from one browser to the
next. Attributes are used to change these default display properties and customize them. There are various
ways to set attribute values for HTML tags. In this course we will set attribute values using cascading style
sheets (CSS). Style sheets allow for efficient and flexible customization of HTML tags especially when the
same tag attribute values are used repeatedly in order to maintain a uniform “look and feel” for multiple
Web pages.
Required HTML Tags
There are three tags that are used to describe the overall structure of a page and provide simple header
information. These are <html>, <head>, and <body>. Let's explore each of these.
<html> - is the first structure tag in every HTML page. Your HTML page must begin with this tag and end
with </html>. The same tag with a backslash in front of it indicates to the browser that this particular
section has concluded.
<head> - specifies that the lines between the beginning and end points of this tag are the prologue to the
rest of the file. Title tags are placed inside the head tags as shown in the example below. The text between
the title tags is the title of the Web page and will appear in the title bar of the browser window. Remember
to close the head with </head>.
<html>
<head>
<title> insert the title here </title>
</head>
<body> - contains the remainder of your HTML page, which includes text, links, image tags, etc. Most of
the important elements of the page are placed between <body> and </body>. You should have only one
pair of opening and ending body tags.
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Creating Web Pages with XHTML: Structuring Content and Adding Images and more Assignments Computer Science in PDF only on Docsity!

Creating Web Pages with XHTML Introduction The HyperText Markup Language (HTML) is a language comprised of a series of coded tags that describe the structure of a document. The idea is that most documents have common elements, such as titles, paragraphs, etc. Because HTML is a markup language, you begin with the text of your page and add special tags around words and paragraphs. These tags indicate different parts of a page and produce different effects in the Web browser. HTML tags are the codes inside brackets (< >) that indicate the features of the page. A text editor can be used to create and edit HTML documents. You can see the HTML code of any Web page by choosing View > Source from the browser's menu bar. HTML tags are not case sensitive, although the newest version of HTML, called XHTML (Extensible Hypertext Markup Language), requires all tags to be written in lowercase. XHTML was designed to improve and standardize HTML. With all that is being put on the Web it will take a long time before most of the HTML on the Web is standardized. Although we will not be running our HTML as strict XHTML, we will start using the standards. Most HTML tags require a corresponding closing tag. The closing tags contain a backslash after the opening bracket. XHTML requires the backslash in the opening tag if a closing tag is not required. The tags can be on the same line with the text or on a line by themselves. When the Enter key is used in the text processor to move to the next line, a new-line character is created which is ignored by HTML. Since extra spaces and blank lines are ignored in HTML, use them to line up the opening and closing tags and to make your code easy to read so you can find errors. HTML does not produce error messages, as programming languages do. Many of the HTML tags can contain attributes. The attributes are listed inside the brackets with their values, . According to the XHTML standards, attribute values should be enclosed in quotes. The corresponding closing tag must not contain attributes. Each HTML tag has a default interpretation in terms of its display properties, which may slightly differ from one browser to the next. Attributes are used to change these default display properties and customize them. There are various ways to set attribute values for HTML tags. In this course we will set attribute values using cascading style sheets (CSS). Style sheets allow for efficient and flexible customization of HTML tags especially when the same tag attribute values are used repeatedly in order to maintain a uniform “look and feel” for multiple Web pages. Required HTML Tags There are three tags that are used to describe the overall structure of a page and provide simple header information. These are , , and . Let's explore each of these. **** - is the first structure tag in every HTML page. Your HTML page must begin with this tag and end with . The same tag with a backslash in front of it indicates to the browser that this particular section has concluded. **** - specifies that the lines between the beginning and end points of this tag are the prologue to the rest of the file. Title tags are placed inside the head tags as shown in the example below. The text between the title tags is the title of the Web page and will appear in the title bar of the browser window. Remember to close the head with .

insert the title here

**** - contains the remainder of your HTML page, which includes text, links, image tags, etc. Most of the important elements of the page are placed between and . You should have only one pair of opening and ending body tags.

Every basic HTML page, therefore, looks like the following code segment:

This is a simple HTML page

... rest of HTML page code including text and tags ...

The Heading Tags Inside the body, you may want to separate your text into headings and paragraphs. The tags used for headings are through , with the largest and the smallest. The largest can be used for headlines, and the smaller headings can be used for the copyright information at the bottom of a Web page. These all have corresponding end tags. Heading tags are rendered differently by different browsers. Here is an example of how to apply a heading tag to a text segment. This is text is a large (h1) heading. The Paragraph Tag The paragraph tag is specified with

. Although the corresponding

tag is optional in the early versions of HTML, it is required in the newest versions and should be used. The paragraph tag forces the text following the tag to drop down and leave a blank space, slightly larger than a blank line, creating a new paragraph. When consecutive paragraph tags are used, most browsers ignore all but the first. The

tag can appear anywhere in the text within the body tags. The following examples produce the same results. Example 1:

Paragraph Example

This is the first paragraph.

This text begins a new paragraph.

This text begins paragraph three.

Example 2: Paragraph Example

This is the first paragraph.

This text begins a new paragraph.

This text begins paragraph three.

The Break Tag The break tag,
, forces a line break. The closing break tag did not exist in early versions of HTML, but now the slash is included in the opening tag. Note that there is a space between the br and the slash in the tag. The space is required for reasons of backward compatibility with older browsers. Use consecutive break tags to create blank lines.

give credit with footnotes or other references. Similarly you can use a few images from Web sites of others if this is a class assignment and you reference their sources on your page. Be sure to list the Web site where the original was found somewhere on your Web page. Web images from any governmental agency such as the White House, NASA, or the South Carolina State government are usually in the public domain, and you can use them without infringement of copyright. Nevertheless, give the reference on your page. If you complete your Web pages for the class and later store them on another general Web domain, such as Geocities, make sure that you have not included any copyrighted materials. The concept of fair use applies to school work only. **_Placing Images on Your Web Page_** To place an image on your Web page, use the image tag, , with the source attribute set equal to the image filename: . Note that there is a required space between the image file name and the slash in the tag. The HTML tag will load the image from the file myDog.gif. You must specify the path name if the file is not in the same directory as the HTML file(s) linking to it. Whereas HTML code is not case sensitive, file names are case sensitive and must be typed exactly as listed in the directory. **_Changing the Size of the Image_** The attributes **height** and **width** can be used to change the height and width of the image either by specifying the percentage of the browser it should occupy or by specifying the exact dimensions in pixels. If an image is enlarged too much or stretched too far in one direction, it will appear distorted. You can change the size, save the HTML file, reload, and see how it looks in the browser to find the size you like. **_Resizing an Image by the Percentage of the Browser Window it Occupies_** The **height** and **width** attributes can be set to a percentage of the browser window size as shown in the example below. As the window is resized by dragging the edge with the mouse, the image will change size proportionally. In the example:

the size of the image in the BlackLab.jpg file will be displayed as half of the browser window's length and width and will change as the window size changes. NOTE: If you used a space before the percent sign and omitted the quotation marks, the code would not work. The quotation marks, although required in the standards, are not actually necessary in the older HTML unless the attribute value contains a space.

Resizing an Image by Specifying its Dimensions in Pixels The height and width attributes can also be set to the height and width of an image in pixels. A pixel, taken from the words "picture element," is the smallest unit on the screen that is capable of changing color. When the value of the height and width attributes are given in numbers without percent signs, the numbers represent number of pixels. In the example:

the image displayed from the file BlackLab.jpg will be quite small, 60 pixels across and 50 pixels down. You may want a much larger image, width="350" height="250", or even larger. Since you have specified the exact number of pixels, resizing the browser window will not change the image size. Experiment with both sizing methods to determine what size image looks best on your Web page.

Spacing the Image with the Paragraph Tag Surround the image tag with two paragraph tags to place the image by itself with a little space above and below the image. Example:

Aligning Images The align attribute can be used in the tag to help place an image where you want it in relation to the window's edge or the adjacent text. The values for the align attribute are left , right , top , bottom , and middle. Left and Right - Using the value left or right will align the image against the left or right edge of the browser window or against the previous image. The text then fills the remaining adjacent portion of the window. Setting the align attribute to left or right can also be used to create a row of images.

The three images will appear side by side across the screen with the top of the images aligned. If the window is resized smaller, the images displayed do not move. Using the same code, when align="left" is omitted in each line; the images will appear side by side aligned on the bottom edge of the images. If the window is not large enough or is resized too small, the images will wrap, one below another. **Top -** The top edge of the image will be aligned with the top of the current line of text. If there are other images in the current line of text, the text will be aligned with the top of the tallest image that came before it in the line. **Bottom -** The bottom edge of the text will be aligned with the bottom edge of the image. This is the default. **Middle** - Netscape will align the middle of the image to the bottom of the current text line even if the text line contains other images. **_More about the Break Tag_** The
tag forces the text line to drop down a line and continue on the left edge of the window or the right edge of a left-justified image. It can be used to position text or images. To position images diagonally down the page, use break tags between the image tags. The break tag can also be used to keep from placing images on top of each other. If you want to continue the text below the image instead of beside it, you can use the **clear** attribute with the
tag. The **clear** attribute, used with left or right aligned images, drops the following text or image down and to the left margin below the image. Using
will drop the next line below the image on the left,
lower than the right-aligned image, and
lower than the lowest image on the left or right margin. For example, if
is used with a left-justified image, the next line of text will appear below the image, not to the right of the image. **Example:**
This text will be aligned with the top of the image and will wrap between the image and the right edge of the window.

Houston Los Angeles Miami New York City

The result in the browser will appear as follows: Large cities in the US  Atlanta  Chicago  Houston  Los Angeles  Miami  New York City Ordered Lists and Numbered Lists An ordered list in HTML creates a numbered list. The list item tag, , is used in front of each item in the list. The items are surrounded by the opening and closing ordered list tags, ... . Example: Largest cities in the US New York City Los Angeles Chicago Houston Atlanta Miami

The browser result will be as follows: Largest cities in the US

  1. New York City

  2. Los Angeles

  3. Chicago

  4. Houston

  5. Atlanta

  6. Miami Nested Lists Lists can be nested to create outlines by putting an ordered list tag, , or an unordered list tag, , after a list item, followed by the sublist items and the appropriate closing list tag ( or ). The browser will use different shaped bullets depending on the level of nesting. In the example below an unordered list is nested below each item of the ordered list. Large cities in the US New York City

     1990 population-19,549,649 2000 population-21,199,865 

Los Angeles

1990 population-14,531,529 2000 population-16,373,645

Chicago

1990 population-8,239,820 2000 population-9,157,540

The following will be the result in the browser window: Large cities in the US 1 1. New York City  1990 population-19,549,  2000 population-21,199,

  1. Los Angeles  1990 population-14,531,  2000 population-16,373,
  2. Chicago  1990 population-8,239,  2000 population-9,157, Definition Lists Definition lists are intended for creating lists of terms and their respective definitions. There are three main tags used in constructing definition lists: , , . Each term is surrounded by the tags and followed by the term’s definition, which is surrounded by the tags. The and tags are used to begin and end the definition list respectively. Example:

HTML Hyper Text Markup Language XHTML Extensible Hyper Text Markup Language CSS Cascading Style Sheet

The following will be the result in the browser window: HTML Hyper Text Markup Language XHTML Extensible Hyper Text Markup Language CSS Cascading Style Sheets

…… rest of the code Text Formatting Attributes You may use the text formatting attributes for customizing any HTML element that could incorporate text such as the body, paragraphs, and headings.  font-family: This attribute is used to set the font type. By default, text appears in Times New Roman on most browsers. You may set this attribute to other font names. Note that the way some fonts are displayed on the browsers may not be very appealing. Test the fonts you wish to use by viewing them on the browser and try to use common fonts.  font-size: This attribute is used to set the font size. By default the text is displayed in 12-point font on most browsers. However, other settings, such as the Text Size property of the browser, factor into how large the text appears on the screen. To set the size of the font, assign the point value you want. For example, use 14pt to indicate 14-point font. You may also set the size to a percentage of the normal font size. For example, use 50% to display the font as half of the size of the normal (default) font size. Finally, the font-size attribute can be set to one of the following xx-small, x-small, smaller, small, medium, large, larger, x-large, xx-large.font-style: This attribute is used to set the style of the font. You may use the values italic , normal , or oblique for this attribute.  font-weight: This attribute is used to set the weight (thickness) of the font. Common values for this attribute are bold, light, bolder, lighter, or normal.  text-decoration: You may add decoration to text by using this attribute which can have values none, underline, overline, line-through, or blink.  color: To set the color of the text, assign values such as the name of a color (e.g. red) or the hexadecimal representation of the color (e.g. #767676) to this attribute. There are many resources on Internal Style Sheet

the Web that provide browser compatible color names as well as hexadecimal color codes. Refer to your class Web site for some of these resources. When setting the color of the text for your Web pages, be sure to view them on a browser to see how they appear to viewers. Pick colors that are easily readable and visible on your pages’ background colors or images.  text-align: You may align text within a Web page element (e.g. paragraph, header, etc.) by setting this attribute to the desired type of alignment. The possible values for this attribute are left, right, center, and justify. Background Attributesbackground-color: This attribute sets the background color of an HTML element. You may use this attribute with the body and paragraph tags. For example, setting the background color for the body tag determines the background color that will fill the browser window when displaying the Web page. The possible values for this attribute are the same as those for the color attribute.  background-image: Use this attribute if you wish to set an image as the background of an element. The value for this attribute is url (---- ) , where the dashes should be replaced by the name of the image file (including the file extension). By default the image will be tiled in the background of the element. The background-repeat attribute discussed below will help in setting the manner in which the background image is displayed.  background-repeat: This attribute sets if and how the background image is to be repeated within the element. The possible values for this attribute are repeat, repeat-x, repeat-y, or no-repeat. The first value is analogous to the default tiled setting. Repeat-x, repeats the background image along the x-axis (horizontal) direction only while repeat-y does the same but along the y-axis (vertical) instead. No- repeat simply places one copy of the image on the page without any repetition in the background. The final display of the background image not only depends on its repeat attribute but also where we position the image relative to the element. For example, if we place it on the top left of the element, then a repeat-y will result in tiling the image along the left edge of the element. If we place it on the top right, repeat-y will result in tiling the image along the right edge of the element instead. To set the position of the background image relative to the element use the background-position attribute discussed below.  background-position: This attribute sets the starting position of the background image with respect to the element. Possible values for this attribute are top left, top center, top right, center left, center center, center right, bottom left, bottom center, and bottom right. Note that each value has two keywords; the first for setting the vertical position and the second for setting the horizontal position of the image within the element. Example: p { background-image: url(pic1.jpg); background-repeat: repeat-y; background-position: top left; background-color: yellow; } pic1.jpg is the image file representing a single light bulb as shown below. Using the paragraph tag in the HTML file will result in the following display in the browser window: Hyperlink Attributes By default, any hyperlinks you insert into your Web pages will appear in blue changing to purple when activated. Depending on your background color or image, these default colors may not be

The paragraph text appears here. The background color is yellow.

The image tiling is repeated until the end of the paragraph.

font-size: 10pt; font-family: Arial; } p.summary { color: red; font-size: 12pt; font-family: Garamond; } To use the two styles created, we simply incorporate their class names in the paragraph tags of HTML documents as shown in the following example. Example:

This is a paragraph that displays the attributes of the p.intro class.

This is a paragraph that displays the attributes of the p.summary class.

This is a normal paragraph. No styles applied.

The three paragraphs will appear in the browser as follows: This is a paragraph that displays the attributes of the p.intro class.

This is a paragraph that displays the attributes of the p.summary

class.

This is a normal paragraph. No styles applied.

CSS also allows for creating generic classes that can be used with multiple HTML elements. For example, suppose that we want to create a class called “red_c” which sets the color attribute of an HTML element to red. So, our style definition would be:

. red_c {color: red;} Note that there is a period before the class name. This class can now be used with any HTML element that has a color attribute. Example: Red Header

This paragraph text is red.

This HTML code will appear in the browser as follows:

Red Header

This paragraph text is red.