370 likes | 516 Views
DePaul University. SNL 262 Web Page Design Tables ! - Chapt 15 Instructor: David A. Lash. HTML Tables. An orderly arrangement of text and/or graphics into vertical columns and horizontal rows. Within HTML tables perform many functions.
E N D
DePaul University SNL 262 Web Page Design Tables! - Chapt 15 Instructor: David A. Lash
HTML Tables • An orderly arrangement of text and/or graphics into vertical columns and horizontal rows. • Within HTML tables perform many functions • Control web page layout (for text and graphics) • Separate a Web page into different areas • Show data output in traditional table format • See example at: http://www.depaul.edu/~dlash/extra/Webpage/examples/examletable.html • Table with integrated graphics • http://www.24hourhtmlcafe.com/hour14/fearful2.htm • Example of table as a page layout device • http://arnb.com/webdesign/chap5/tables/advert.htm
HTML Tables • An orderly arrangement of text and/or graphics into vertical columns and horizontal rows. Each these are called a “cell”
The Basic Table Structure The bare minimum tags needed to describe a table are <TABLE> … </TABLE>, <TR> … </TR>, <TD> … </TD> Encloses TABLE Defn Start & End Table row Start & End Table Colmn
The Basic Table Structure <HTML> <HEAD><TITLE> Simple Table </TITLE> </HEAD> <BODY> <TABLE> <TR> <TD> Cell 1</TD><TD>Cell 2</TD> </TR><TR> <TD> Cell 3</TD><TD>Cell 4</TD> </TR> </TABLE> </BODY> </HTML> Table Row Start & End Table Table Column Creates the example 4 cell table Click Here http://condor.depaul.edu/~dlash/website/basic.html
Guess The Table Format - 1? What would the following display? <TABLE> <TR> <TD> Cell 1</TD><TD>Cell 2</TD> </TR><TR> <TD> Cell 1</TD><TD>Cell 2</TD><TD>Cell 3</TD> </TR> </TABLE> Click Here for answer http://www.depaul.edu/~dlash/website/guess1table.html
Guess The Table Format - 2? What would the following display? <TABLE> <TR> <TD>Cell1</TD> <TD>Cell2</TD> <TD></TD> </TR><TR> <TD> Cell </TD> </TR><TR> <TD> Cell 1</TD> <TD>Cell 2</TD> <TD>Cell 3</TD> </TR> </TABLE> Click Here for answer http://www.depaul.edu/~dlash/website/guess2table.html
Guess The Table Format - 3? What would the following display? <TABLE> <TR> <TD>Cell1</TD> <TD>Cell2</TD> <TD></TD> <TD></TD> <TD>Cell ? </TD> </TR><TR> <TD> Cell 1</TD> <TD>Cell 2</TD> <TD>Cell 3</TD> </TR> </TABLE> Row 1 w/ 5 cols Col 3-4 empty Col 5 Row 2 Cols 1-3 only have data Click Here for answer http://www.depaul.edu/~dlash/extra/Webpage/examples/guess3table.html
Introducing the <TH> Another basic but option TAG is the <TH> similar to <TD> <TABLE> <TR> <TH> Col 1 </TH> <TH> Col 2 </TH> </TR><TR> <TD> Cell 1</TD><TD>Cell 2</TD> </TR><TR> <TD> Cell 1</TD><TD>Cell 2</TD> </TR> </TABLE> Automatic Bold & center Click Here for example http://www.depaul.edu/~dlash/website/simpletablewTH.html
Another Example • <HTML> • <HEAD><TITLE> My First Table </TITLE> </HEAD> • <BODY> <TABLE> • <TR> <TH> Description <TH> Size<TH> Weight</TR> • <TR><TD>Gun<TD>5 Inch Barrel <TD> 20 Ounces</TR> • <TR><TD>T-Rex<TD>40 Feet High <TD> Multiple Tons</TR> • <TR><TD>Hurricane Floyd<TD>400 Miles Radius <TD> ???? • </TR> • </TABLE> • </BODY></HTML> • (Sometime can get by w/o closing tags • </TD>, </TH>, </TR> but this is risky business • (e.g., I.E., VS Navigator.) Click Here for example http://www.depaul.edu/~dlash/website/TableEx.html
Tables Are Their Own Environment <HTML> <HEAD><TITLE> My First Table </TITLE> <BODY> <B> <TABLE> <TR> <TH> Description </TH> <TH> Size</TH><TH> Weight </TH> </TR> <TR> <TD>Gun</TD><TD>5 Inch Barrel</TD> <TD> 20 Ounces</TD> </TR> <TR> <TD>T-Rex</TD><TD>40 Feet High </TD> <TD> Multiple Tons</TD> </TR> <TR> <TD>Hurricane Floyd</TD><TD>400 Miles Radius</TD> <TD> ????</TD> </TR> </TABLE> </B> </BODY></HTML> You’d think each element in the table would be bold Instead that bold is ignored w/I table
Table Cells Format Like Documents... <html><head> <title> Test </title> </head> <body> <table border=1> <tr> <td>Cell1 <font color=blue> <ol> <li> Happy <li> Days </ol></td> <td> Are here again. </td></tr> <tr><td> The <i>skies</i> are are <b>blue</b> again </td> <td> <img src="../donald.gif"> </td> </tr> </table> </body> </html>
Options: Table, Row and Column Width Some other attributes for the table tag • width=number, percentage - specifies the width (in pixels) of entire window or % of size of current element. (Can be set at table, row or cell level.) • height=number, percentage - specifies the height (in pixels) of entire window or % of size of current window. (Can be set at table, row or cell level.)
Specifying Column Size Sets the overall sizes <HTML> <HEAD><TITLE> My First Table </TITLE> <BODY> <TABLE WIDTH=500 HEIGHT=400> <TR> <TH WIDTH=10%> Description </TH> <TH WIDTH=40%> Size </TH> <TH WIDTH=40%> Weight </TH> </TR> <TR> <TD WIDTH=10%>Gun</TD> <TD>5 Inch Barrel </TD> <TD> 20 Ounces </TD> </TR> <TR> <TD WIDTH=10%>T-REX</TD><TD>40 Feet High</TD> <TD> Multiple Tons</TD> </TR> <TR> <TD WIDTH=10%>Hurricane Floyd</TD> <TD>400 Miles Radius </TD><TD> ???? </TD> </TR> </TABLE> </BODY></HTML> Click Here http://www.depaul.edu/~dlash/website/TableEx3.html Sets individual element
Options: Borders Some other attributes for the table tag • border=# - 0 or no border is the default see below for more details.
Implementing Borders <HTML> <HEAD><TITLE> My First Table </TITLE></HEAD> <BODY> <TABLE BORDER=3 WIDTH=500 HEIGHT=400> <TR> <TH WIDTH=10%> Description </TH> <TH WIDTH=40%>Size</TH> <TH WIDTH=40%> Weight</TH> </TR><TR> <TD WIDTH=10%>Gun<TD>5 Inch Barrel </TD> <TD> 20 Ounces </TD> </TR><TR> <TD WIDTH=10%>T-REX</TD> <TD>40 Feet High</TD> <TD> Multiple Tons </TD> </TR><TR> <TD WIDTH=10%>Hurricane Floyd </TD> <TD>400 Miles Radius</TD><TD>????</TD> </TR> </TABLE> </BODY></HTML> Example at http://www.depaul.edu/~dlash/website/TableEx5.html
Options: Background color • bgcolor="#rrggbb" or color name - sets a color for background for table or table cell.
Tables and BGCOLOR • Can use BGCOLOR= attribute in the TABLE,TR or TD tag. <HTML> <HEAD><TITLE> Color MyTable </TITLE> <BODY> <B> <center> <FONT SIZE="+3">The Local News </FONT></center> <TABLE BORDER=1 BGCOLOR="RED"> <TR> <TD>TEXT</TD><TD>TEXT</TD><TD>TEXT</TD> </TR><TR BGCOLOR="GREEN"> <TD>TEXT</TD><TD>TEXT</TD> <TD BGCOLOR="YELLOW">TEXT</TD> </TR> <TR> <TD>TEXT</TD><TD>TEXT</TD><TD>TEXT</TD> </TR> </TABLE> </BODY></HTML>
Some Special Table Tricks • Cell text alignment • Padding the columns and Rows • Spanning Columns and Rows • Special Examples
Options: Alignment Some other attributes for the table tag • align=left|right|center – sets the horizontal alignment for a table, row, or cell. Can be used with <TABLE> <TR>, <TD> or <TH> tags. • valign=top|bottom|middle – set the vertical alignment of the table, row or cell. Can be used with <TABLE>, <TR>, <TD> or <TH> tags.
Options: Alignment <HTML> <HEAD><TITLE> My First Table </TITLE> <BODY> <TABLE BORDER=2 WIDTH=500 HIEGHT=500> <TR> <TH> Name </TH> <TH> Rank</TH> <TH> Serial Number</TH> </TR><TR> <TD ALIGN=RIGHT>George Washington</TD> <TD>General </TD> <TD> 1</TD> </TR> <TR> <TD ALIGN=CENTER>George Bush</TD> <TD>President </TD> <TD ALIGN=RIGHT> 42</TD> </TR> <TR ALIGN=RIGHT> <TD ALIGN=LEFT>George Ryan </TD> <TD>??? </TD> <TD> ????? </TD> </TR> </TABLE></BODY></HTML> • http://condor.depaul.edu/~dlash/website/TableEx6.html
Cell padding and cell spacing • Cell padding specifies the number of pixels from the cell border to the text. Useful for simple announcement boxes. • Cell spacing specifies number of pixels between cells of the table. Spacing Number of pixels betw cells Text Text Padding Number of pixels from cell border to text
Cell Padding And Spacing • Cell padding specifies the number of pixels from the cell border to the text. Useful for simple announcement boxes. <HTML> <HEAD><TITLE> Color MyTable </TITLE> <BODY> <B> <center> <FONT SIZE="+3">The Local News </FONT></center> <DIV ALIGN=CENTER> <TABLE BORDER=2 CELLSPACING=0 CELLPADDING=52> <TR> <TD ALIGN=CENTER BGCOLOR="RED" VALIGN=middle><B>Announcing Earlier Class Dismissal Today!</B> </TD></TR> </TABLE> </DIV> </BODY></HTML> 1 Row 1 Col (A Box!) Start text 52 pixels from border (next slide http://www.depaul.edu/~dlash/website/Announce.html
Cell Padding And Spacing • Cell spacing specifies number of pixels between cells of the table. <HTML> <HEAD><TITLE> Color MyTable </TITLE> <BODY> <B> <center> <FONT SIZE="+3">The Local News </FONT></center> <DIV ALIGN=CENTER> <TABLE BORDER=2 CELLSPACING=50 CELLPADDING=1> <TR><TD>DATA1</TD><TD>DATA2</TD></TR> <TR><TD>DATA3</TD><TD>DATA4</TD></TR> </TABLE> </DIV> </BODY></HTML> • (next slide http://www.depaul.edu/~dlash/website/Cellspacing.html) 50 pixels between table cells
Options: colspan and rowspan • colspan - Allows a cell to span columns • rowspan - Allows a cell to span rows • Useful for performing a page layout
Column & Row Spacing • Colspan allows 1 cell to span more than 1 Columns of cells. This row has colspan=2 This row has colspan=3 This row has colspan=2
Col Span Example 3 rows & Cols. The first row spans all cols! • Example Colspan <HTML> <HEAD><TITLE> Color MyTable </TITLE> <BODY<FONT SIZE="+3">The Local News </FONT> <TABLE BORDER=1 BGCOLOR="RED"> <TR> <TD COLSPAN=3 BGCOLOR="blue">TEXT</TD> <TR> <TD>TEXT</TD><TD BGCOLOR="BLUE">TEXT</TD><TD BGCOLOR="YELLOW">TEXT</TD> </TR><TR> <TD>TEXT</TD><TD BGCOLOR="BLUE">TEXT</TD><TD BGCOLOR="ORANGE">TEXT</TD> </TR> </TABLE></BODY></HTML> • http://www.depaul.edu/~dlash/website/Colspan_example.html
Col & Row Spacing • Rowspan allows 1 cell to span more than 1 rows of cells. This col has rowspan=3 This col spans both cols rowspan=2 This col has rowspan=3
RowSpan Example 3 rows & Cols. The first col spans all rows! • Just like Col Span but with rows! <HTML> <HEAD><TITLE> Color MyTable </TITLE> <BODY> <center> <FONT SIZE="+3">The Local News </FONT></center> <TABLE BORDER=1 BGCOLOR="RED"> <TR> <TD ROWSPAN=3 BGCOLOR="blue">TEXT</TD><TD BGCOLOR="YELLOW">TEXT</TD><TD BGCOLOR="ORANGE">TEXT</TD> </TR><TR > <TD>TEXT</TD><TD BGCOLOR="BLUE">TEXT</TD> </TR><TR> <TD BGCOLOR="BLUE">TEXT</TD><TD BGCOLOR="ORANGE">TEXT</TD> </TR></TABLE></BODY></HTML> • http://www.depaul.edu/~dlash/website/Rowspan.html
Creating Layouts • Suppose you want to make a page layout as follows: Your Logo Title This Col has colspan 5 N a v i g a t i o n Main Page rowspan 4 colspan 4 rowspan 4
Wouldn’t this solve the problem? <HTML> <HEAD> <TITLE> Sample Table </TITLE> </HEAD> <BODY> <TABLE BORDER=1 height=100% width=100%> <TR> <TD width=15%> <img src=donald.gif > </TD> <TD colspan=4> Title </TD> </TR> <TR> <TD width=15%> <UL> <LI> Nav1</LI> <LI> Nav2 </LI> <LI> Nav3 </LI> </OL> </TD> <TD colspan=4> Main Body </TD> </TR> </TABLE> 1st col 15% of screen Span title Put Nav Items In BL Put Main Body in • See how this would display http://www.depaul.edu/~dlash/website/layout1.html
Would Output ... Title and body not centered Navigation not upper right hand corner
Lets Refine It ... Center In cell <HTML> <HEAD> <TITLE> Sample Table </TITLE> </HEAD> <BODY> <TABLE BORDER=1 height=100% width=100%> <TR> <TD align=center width=15%> <img src=donald.gif > </TD> <TD colspan=4 align=center> Title </TD> </TR> <TR> <TD width=15% valign=top> <OL> <LI> Nav1</LI> <LI> Nav2 </LI> <LI> Nav3 </LI> </OL> </TD> <TD colspan=4> <TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR> <TD align=center valign=middle><font size=+2> Main Body </font></TD> </TR> </TABLE> </TR> </TABLE> </BODY></HTML> Start New table Valign at Top Of cell Align in Center of cell • Next slide http://www.depaul.edu/~dlash/website/layout2.html
Some Special Table Uses • Goto This Web Page - Click Here