|
More HTML Contents This section includes a few basic HTML concepts that you'll need to create useful web pages. It doesn't give detailed instructions or exhaustive lists of all the tags and attributes you'll need; for that, see some of the references in Additional Resources. Rather, it introduces a few of the most useful concepts and terms for basic web design. Advice: Don't get carried away. Keep everything (especially graphics) small and readable. Large file sizes means longer download times, which will annoy people with slow connections. Too many complex graphics and poor color choices make a page hard to read. For more good advice, consult LSIT's Design Guidelines. What makes the web a web is the prevalence of links. When you click on text marked as a link, it takes you to another document somewhere on the Web. Another Website The way to indicate a link to another website is to enclose the text in the <a> ("anchor") tag, and put the URL you're linking to (in quotes) as the value of the href attribute of that tag. The text in the <a> tag will display underlined and colored.
This displays as:
This type of link is called an "absolute URL", because it gives the full address of the destination page. Another page on your site If you're linking to a page at your own site, you should use a "relative URL", which specifies the page location relative to the current file. If the page you're linking to is in the same directory, all you need is the file name:
If the page you're linking to is in another directory, you can use the conventions you're familiar with from DOS. Two dots stands for "one directory up" (e.g. "../webpage.htm" would refer to a file in the parent directory); for a subdirectory you use the directory name followed by a slash (e.g. "subpages/webpage.htm" refers to a file in the 'subpages' subdirectory.) The reason you should use relative URLs whenever possible is that then you can set up your website on your local machine and test it there, and then upload it, without changing any of the links; you can even move it to another server and the links stay the same. Another place on the same page To link to another part of the same page (like the "contents" links at the top of this page), you need to insert a "named anchor" (like a bookmark in Word) at the location you want to link to. This is just an a tag with no contents and a name attribute. For instance, the anchor at the top of this section looks like this:
Then to jump to the named location, you just use a regular link tag where the href value the anchor name. The link to this section in the "contents" at the top of this page looks like this:
A link to download a file If you have a non-html file you want to let people download to their computer, such as a Word document, a sound file, or a zipped collection of files, all you have to do is put the file on your site and link to it. When somebody else visits your site and clicks the link, if the file is in a format their browser doesn't understand, the browser will offer to download it rather than displaying it. For instance, the following code would link to the file "SusannaFonts.zip", a compressed file containing two fonts:
This displays as follows: Clicking this link should result in an offer to download the font. Which file types a particular browser will attempt to display depends on what "plugins" the browser has installed. Internet Explorer, for instance, will display a Word .doc file rather than downloading it; a .wav file would probably be loaded and played in a media player application. To avoid this it's a good idea to compress files you want people to download; this also reduces download times. Linking with an image Websites often use images rather than text for links. To use an image link, put the <a> and </a> tags around an image tag, instead of around text. Most modern web pages make more or less extensive use of images. Images live in separate files from the HTML and text; you include an image in a web page simply by including a link to the image, usually as the value of the src ("source") attribute of the <img> ("image") tag. (Again, you should always use relative links if possible.) The image tag has various attributes relating to the size and position of the image. For instance, the following code:
The "width" and "height" attributes (measured in pixels) are optional, but including them is recommended so that your page will save the right amount of space for the image as the image loads. (Images usually load more slowly than text.) Another way you can use graphics on your page is to tile them over the background of the whole page or part of it. Text and other elements then appear on top of the image. You do this by using the image URL as the value of the "background" attribute of the "body" tag. This approach should be used with care, since it can easily make text completely unreadable. Here's an example of a page with a tiled background. (The text in this page is mostly in a table with a solid background.) You can't use just any computer graphics file on the Web. There are two main image file formats in use. Since graphics files tend to be large and thus take a long time to download, both are compressed; but they use different types of compression.
There is another new file format, ".png" ("Portable Network Graphics") that is gaining acceptance, but it is not yet widely supported so I won't discuss it further here. So -- to use graphics on the Web, you will have to convert them to either GIF or JPG format if they are not in one of those formats already. Just about any graphics program can do this, including the most current version of Windows Paint (the free graphics program that comes with Windows -- look in Accessories).
By default, HTML text stretches from edge to edge of the window. However, you won't see many web pages that have that organization. Usually, there are extra elements, for decoration or navigation, above or to the left or right of the main text. These types of page layouts are produced in one of two ways: tables and frames. Tables Most Web pages (this one, for instance) use a table layout. This is the most common layout:
Table cells can be formatted independently: for instance, they can have different text alignments, colors, or bitmapped backgrounds from each other. Tables can also be nested inside other tables. It is much easier to design a table using an authoring program like Dreamweaver than by hand. However, it helps to know a little about how the HTML is set up. A table in HTML has a hierarchical structure:
Any of these elements can have attributes for color, font, background image etc. By default, HTML tables are autosizing: columns will change width to accomodate the text and graphics placed in them. If you want to specify a size, you can give an absolute size (in pixels) or a relative size (a percentage of the width of the element's container). Since screen sizes vary, it's preferable to use percentages. The HTML for the small table above is as follows:
This illustrates the general structure of a table. If you're interested in the details of the attributes of the various tags, consult the links in Additional Resources. Frames If you want the parts of your page layout to scroll independently, you can use frames. Frames give you the ability to combine several different HTML files on a single page. There is a matrix page which contains the "frameset", and then separate daughter pages for each frame in the set. Databases for Linguists is an example of a site which uses a frame layout: the navigation links are in the left frame and the text is in the right frame. When you scroll the text, the links all stay visible. The links are actually in a separate HTML file from the text. The details of how to set up frames in HTML are a bit complex, so I won't go into them here. Consult the links in Additional Resources.
|
|
|||||||||||||||||||||||||||