|
Writing HTML | About | FAQ | References | Tags | Lessons | previous | next |20. Extra AlignmentWhy just stay over to the left? ... when you can move to the right? or just hang out in the middle? ObjectivesAfter this lesson you will be able to:
LessonNote: If you do not have the working documents from the previous lessons, download a copy now. Also, you may want to first look at the test page to see if your browser supports the tags used in this lesson. Text AlignmentAs the web grew and grew and grew, there was demand for more control over page layout. One desire was to format text that was aligned to the center of a page, rather then just justified to the left margin. This gets into one of those sticky Netscape versus "standard" HTML situations. Netscape introduced an HTML extensions -- <center>...</center> tag -- it aligns everything inside the tags with the center of the web page. Seems to make sense? Well, if you talk to a mark-up language purist, alignment is an attribute. The more general HTML (and "standard") for center alignment is a variation on the <p> tag: <p align=center> blah blah blah <img src="file.gif"><br> blah blah </p> Note that now there is a closing </p> tag. This becomes important later when we get into Style Sheets and other design features of HTML 4.0. Also, if you are center aligning several paragraphs, each one will have to be marked with a separate <p align=center>...</p> Most other browsers and the HTML 3.2 standards now support Netscape's <center>...</center> tags. Remember that if a browser does not support a tag, it will just ignore it. For the effect of center alignment, compare:
with this example that center aligns the content:
Now we will modify our cover page (index.html) to use the <center>...</center> tag on the list of lesson sections. We will also make some other changes to improve its appearance.
NOTE: Look closely at the changes we have made. This whole section is enclosed in the <p align=center>..</p> tags for alignment. The unordered list we built in lesson 6 would look odd centered -- the bullet marks would be staggered. So we have removed the <ul><li>...<li>...</ul> structure. The <br> tags at the end of each line will force a line break. You may want to compare your HTML file to an example of how it should look at this point. Any header <hN>...</hN> tag may be center aligned by adding the attribute: <hN align=center>blah blah blah</hN> We will now use this attribute to center the title of each web page:
NOTE: There is also an align attribute for the <hr> tag that is relevant to the other options we reviewed in lesson 19 "Easy Horizontal Rules". When you specify a shorter width for a horizontal rule, you can also specify that it be aligned to the left or the right (the default is to center align horizontal rule lines):
Aligning Images and TextIn lesson 7a we learned how to put images in our pages and saw that we could have one line of text align with the top, middle, or bottom of an image. However, up to now, we could not have a block of text sitting side by side with an inline image. With the align attribute in the <img> tag we can specify to have the image itself aligned to the right or left margin of the page. But more so, we can have any HTML following it "fill" in around the empty space. The HTML to do this is: <img src="filename.gif" align=right> <img src="filename.gif" align=left> Compare these two examples:
Shrink and stretch your web browser window to see how it affects your page with aligned images/text. One more note. There will be times when the text or other items that are aligned with the image are rather short and you want to force the next text to jump down below the image. There is an attribute for the <br> tag to clear the alignment: <br clear=left> <br clear=right> <br clear=all> that will "clear" (or disable) any preceding alignments set up in the <img> tags. We suggest that you always use these tags because the alignment will vary depending on the font specified in the reader's web browser and the width of their browser window. Image Space PaddingSometimes when you use the right or left alignment with an image, the text wraps a bit too close to the image. There is an option you can add to the <img> tags to add more padding or space around your image: <img scr="my_image.gif" alt="My Image" width=79 height=142 vspace=8 hspace=12> The vspace and hspace options put the amount of pixels specied of space oabove and below (vspace) or on the left and the right (hspace) of the image. So we could modify our example above to look like:
Adding Image Alignment to our Volcano SiteWe will now return to our index.html page to re-format the opening screen. The picture may look nice, but it takes more vertical space to have the picture followed by the text below. We will use the image/text alignment to put some of the text adjacent to the image.
NOTE: Everything between the <img... align=left> tag and the <br clear=left> tag will be placed adjacent to the picture -- the image is aligned left and the other HTML fills the empty space. You may want to compare your HTML file to an example of how it should look at this point. Text Justification/AlignmentWe will add in one more alignment tag, the "divisions" tag <div>...</div>, introduced as part of HTML 3.0. All text within the tag is justified according to the align attribute: <div align=left>...</div> <div align=right>...</div> <div align=center>...</div> Note that the center attribute accomplishes the same effect as the Netscape <center>...</center> tag. We will now use this tag to make the opening quotation on our cover page have its text aligned to the right margin of the page:
Check Your WorkCompare your web pages with this sample of how it should appear. If your pages are different from the sample or the hypertext links do not work correctly, review the text you entered in the text editor. ReviewReview topics for this lesson:
Independent PracticeTry making some of your text centered- aligned or right margin aligned. Coming Next....
GO TO.... | Lesson Index | previous: "Easy Horizontal Rules" | next: "Tables" |
Writing HTML: Lesson 20: Extra Alignment |