Friday, April 8, 2011

Web Design tutorial part 5

6-1 Introduction
We started our study on tables in previous lesson and We will continue our study in this lesson. As I told you in previous lesson, tables are very important in professional web design. You will need them for holding pictures, buttons, text etc.
In this lesson we will cover more options about table cells, cell padding, cell spacing and finally we will learn how to link different parts of an image to different locations on the web.

6-2 Cell Width (Column Width)
In previous lesson we learned how we can determine width and height of a table.
<HTML>
<HEAD>
<TITLE>Table: Column widths not specified</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=400 HEIGHT=100 BORDER=3>
<TR>
<TD>TOP LEFT</TD>
<TD>TOP RIGHT</TD>
</TR>
<TR>
<TD>BOTTOM LEFT</TD>
<TD>BOTTOM RIGHT</TD>
</TR>
</TABLE>
</BODY>
</HTML>
In above table we have not determined sizes for two cells in first row. In this way you will not be able to say how will these cells display in different browsers and different screen modes.
You can determine width of each column in your table by specifying width of cells in first row. Just be careful
about correctness of sizes you specify. For example if your table width is 200 pixels sum of cell widths must be exactly 200.

<HTML>
<HEAD>
<TITLE>Example 6-1a</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=400 HEIGHT=100 BORDER=3>
<TR>
<TD WIDTH=140>TOP LEFT</TD>
<TD WIDTH=260>TOP RIGHT</TD>
</TR>
<TR>
<TD>BOTTOM LEFT</TD>
<TD>BOTTOM RIGHT</TD>
</TR>
</TABLE>
</BODY>
</HTML>
You can also determine cell widths in percent. Sum of cell width percentages must be 100%.

<HTML>
<HEAD>
<TITLE>Example 6-1b</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=400 HEIGHT=100 BORDER=3>
<TR>
<TD WIDTH=35%>TOP LEFT</TD>
<TD WIDTH=65%>TOP RIGHT</TD>
</TR>
<TR>
<TD>BOTTOM LEFT</TD>
<TD>BOTTOM RIGHT</TD>
</TR>
</TABLE>
</BODY>
</HTML>
When you determine sizes of first row cells you will not need to determine widths for second row cells.
If you want a cell to be empty, you cannot omit definition for that cell. Insert cell definition, and enter a &nbsp; between <TD></TD> tags .As we told in later lessons this means a space character. You must enter at least a space in this form if you need an empty cell.Otherwise area of that cell will not apear like an empty cell.

<HTML>
<HEAD>
<TITLE>Example 6-2</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=400 HEIGHT=100 BORDER=3>
<TR>
<TD WIDTH=140>TOP LEFT</TD>
<TD WIDTH=260>&nbsp;</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>BOTTOM RIGHT</TD>
</TR>
</TABLE>
</BODY>
</HTML>
In above example we have two empty cells but as we have specified both table and cell sizes, table will not lose it's shape. If we remove sizes, we cannot guarantee how it will be displayed on different browsers and screen modes. For the above reason we suggest you to determine table sizes in every table you use. Using fixed sizes is not a good idea. Use percent sizes instead of fixed sizes.

6-3 Cell padding
You can specify two other important size parameters for a table. Cell padding is the space between cell borders and table contents such as text, image etc.

<HTML>
<HEAD>
<TITLE>Example 6-3</TITLE>
</HEAD>
<BODY>
Cell padding effect : <BR><BR>
<TABLE BORDER=3 CELLPADDING=20>
<TR>
<TD>TOP LEFT</TD>
<TD>TOP RIGHT</TD>
</TR>
<TR>
<TD>BOTTOM LEFT</TD>
<TD>BOTTOM RIGHT</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Default value for this option is 1. It means that contents of a cell will have a distance of one pixel with borders. If you don't want any space between object inside the cells and its borders you can determine the value of 0 for this option.

6-4 Cell spacing

Cell spacing parameter determines the space between inner and outer parts of a table. In fact a table is constructed form two borders . A border area and a cell area. There is a space between cell area and outer border. We call this "cell spacing". If you increase this value you will have a thick border. Default value for this property is 2. If you specify 0 for it, you will have a very thin border.

<HTML>
<HEAD>
<TITLE>Example 6-4</TITLE>
</HEAD>
<BODY>
Cell spacing effect : <BR><BR>
<TABLE BORDER=3 CELLSPACING=10>
<TR>
<TD>TOP LEFT</TD>
<TD>TOP RIGHT</TD>
</TR>
<TR>
<TD>BOTTOM LEFT</TD>
<TD>BOTTOM RIGHT</TD>
</TR>
</TABLE>
</BODY>
</HTML>
You can also mix cell spacing and cell padding options to make specific tables that you need.

6-5 Tables and images

Sometimes you need an image that when users clicks on different parts of it they go to different pages. In previous lessons you learned how to use an image as a link to another address or page. In this special case you will need to cut your picture into as many parts as you need and insert them in a table that holds image parts beside each other. Then you will link each image part to a different page.
You will also need to set both cell spacing and cell padding to the value of 0 to prevent the table to be seen between image parts. In this way users will see a single image but when they click on different parts of image they will go to different addresses.

6-6 Working with graphic editing programs
As a web designer you need a graphics manipulation program.There are many professional programs in the market. Photoshop is a very professional and powerful program but it is an expensive program. You can
use PaintShop Pro instead. This is another professional but easy program. You can even download limited versions of this program from many download sites.
These programs will enable you to cut pictures into parts, add many effects on your graphics, decrease graphics size etc.

7-1 Table background color
We can use background colors for tables in new browsers. You can specify background color options inside <TABLE> tag.

<HTML>
<HEAD>
<TITLE>Example 7-1</TITLE>
</HEAD>
<BODY>
<TABLE width="300" BGCOLOR="#66CCFF">
<TR>
<TD width="50%">A</TD>
<TD width="50%">B</TD>
</TR>
<TR>
<TD width="50%">C</TD>
<TD width="50%">D</TD>
</TR>
</TABLE>
</BODY>
</HTML>
In above example entire table will change to new color even table borders. You can also determine background color for each row of your table. If you want to do this, you must use BGCOLOR option inside <TR> tag of the desired row.
This second method will only change colors of cells in specified row.

<HTML>
<HEAD>
<TITLE>Example 7-2</TITLE>
</HEAD>
<BODY>
<TABLE width="300" BORDER=1>
<TR BGCOLOR="#66CCFF">
<TD width="50%">A</TD>
<TD width="50%">B</TD>
</TR>
<TR BGCOLOR="#CCFFFF">
<TD width="50%">C</TD>
<TD width="50%">D</TD>
</TR>
</TABLE>
</BODY>
</HTML>
You can even change color of individual cells by using BGCOLOR option in <TD> </TD> cell tags.
You can mix all above options to create your desired table.
In next example we will change color of first row to "#336699". Then we will change color of two cells in second row to "#66CCFF" and "#CCFFFF" respectively.

<HTML>
<HEAD>
<TITLE>Example 7-3</TITLE>
</HEAD>
<BODY>
<TABLE width="300" BORDER=1>
<TR BGCOLOR="#336699">
<TD width="50%">A</TD>
<TD width="50%">B</TD>
</TR>
<TR>
<TD width="50%" BGCOLOR="#66CCFF">C</TD>
<TD width="50%" BGCOLOR="#CCFFFF">D</TD>
</TR>
</TABLE>
</BODY>
</HTML>

7-2 Column Span

Sometimes you need to join two cells in a row to each other. For example in a 2*3 table we may want to join two cells with each other . In this way we will have two cells in first row and three cells in second row. Enter this html code in a file and browse it in your browser to see what is column span.

<HTML>
<HEAD>
<TITLE>Example 7-4</TITLE>
</HEAD>
<BODY>
<TABLE BORDER=1>
<TR>
<TD COLSPAN=2>A</TD>
<TD>B</TD>
</TR>
<TR>
<TD>A</TD>
<TD>B</TD>
<TD>C</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Just be careful that when you have for example 2 cells in first row and first one uses column span parameter COLSPAN=2 it means that it is equal to two cells. Therefore you must have three cells in next row (three <TR> tags) or you may use COLSPAN to create cells that when you add them, it will be equal to previous row or 3 in this example.

7-3 Row Span
This time we want to join two cells in a column (from different rows). This is the same as previous section with the difference that we will join cells from different rows rather than cells in different columns. This time we must use ROWSPAN instead of COLSPAN.

<HTML>
<HEAD>
<TITLE>Example 7-5</TITLE>
</HEAD>
<BODY>
<TABLE BORDER="1" WIDTH="200">
<TR>
<TD ROWSPAN="2">A</TD>
<TD>B</TD>
<TD>C</TD>
</TR>
<TR>
<TD>D</TD>
<TD>E</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Again you must be careful that when you have for example a cell in first column that you have joined two cells to create it using the option ROWSPAN=2 then your table must have two rows and you must take this in mind in next parts of your table. In above example we only entered two cells in second row (started from second <TR> ) as first cell of first row has occupied first cell of this row too and we have only two cells left of 3 cells. Enter this example and browse it to see the results.
You may want to mix these tags to create your custom tables however this is a complicated task and you must work hard to gain needed experience with these tables.

7-4 Nested Tables
Yes we can nest tables in each other. If you are going to design complicated web pages you will always do this. For example you need a table with border size of 3 in a specific part of a web page. To fix position of that table in your desired place you will need a table with border size of 0. In this case first table can be seen as its border size is 2 but second one will not be seen as you used it just for positioning of first table.
Anyway, writing a nested table code is easy.

<HTML>
<HEAD>
<TITLE>Example 7-6</TITLE>
</HEAD>
<BODY>
<TABLE border="0" width="750">
<TR>
<TD width="25%">&nbsp;</TD>
<TD width="25%">&nbsp;</TD>
<TD width="25%">
<TABLE border="2" width="100%">
<TR>
<TD width="50%">1-</TD>
<TD width="50%">HTML</TD>
</TR>
<TR>
<TD width="50%">2-</TD>
<TD width="50%">C Prog.</TD>
</TR>
<TR>
<TD width="50%">3-</TD>
<TD width="50%">JScript</TD>
</TR>
</TABLE>
</TD>
<TD width="25%">&nbsp;</TD>
</TR>
</TABLE>
</BODY>
</HTML>
In this example we have a 1*4 table. We want to hold our main table inside this table in its third column so that our main table will be shown in right side of the center of the screen. Main table has a border size of 1 while first table is hidden.

That's it and hope you could learn the basic essence of web design :) !

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Grants For Single Moms