76
Chapter 5 Working with Tables Principles of Web Design, 4 th Edition

Chapter 5 Working with Tables

  • Upload
    bracha

  • View
    63

  • Download
    5

Embed Size (px)

DESCRIPTION

Chapter 5 Working with Tables. Principles of Web Design, 4 th Edition. Objectives. Understand table basics Format tables Follow table pointers to create well-designed tables Create a page template Evaluate examples of page templates. Understanding Table Basics. Using Table Elements. - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter 5 Working with Tables

Chapter 5

Working with Tables

Principles of Web Design, 4th Edition

Page 2: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-2

Objectives

• Understand table basics• Format tables• Follow table pointers to create well-designed

tables• Create a page template• Evaluate examples of page templates

Page 3: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-3

Understanding Table Basics

Page 4: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-4

Using Table Elements

• To build effective page templates, you must be familiar with the HTML table elements and attributes

• The <table> element contains the table information, which consists of table row elements <tr> and individual table data cells <td>

– These are the three elements you will use most frequently when you are building tables

Page 5: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-5

Page 6: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-6

Page 7: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-7

Page 8: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-8

Basic Table Code<table border="1">

<tr><td>Breed</td><td>Description</td><td>Group</td>

</tr>

<tr><td>French Bulldog</td><td>Loyal Companion</td>

<td>Non-Sporting</td></tr>

<tr><td>Wheaten Terrier</td><td>High energy, friendly</td>

<td>Terrier</td></tr>

<tr><td>English Pointer</td><td>Hunting companion</td>

<td>Sporting</td></tr>

<tr><td>Australian Cattle Dog</td><td>Guarding, herding</td>

<td>Working</td></tr>

</table>

Page 9: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-9

Captions and Table Header

• <caption> lets you add a caption to the top or bottom of the table

• By default, captions display at the top of the table; you can use the align=“bottom” attribute to align the caption at the bottom of the table

• The <th> tag lets you create a table header cell that presents the cell content as bold and centered

Page 10: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-10

Page 11: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-11

Table Grouping Attributes

• The primary use of the grouping elements is to let you apply styles to groups of either rows or columns

Page 12: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-12

Page 13: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-13

Page 14: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-14

Defining Table Attributes

• Table attributes let you further define a number of table characteristics

• You can apply attributes at three levels of table structure: global, row level, or cell level

Page 15: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-15

Global Table Attributes

• Global attributes affect the entire table

Page 16: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-16

Row-Level Table Attributes

• Row-level attributes affect the entire table

Page 17: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-17

Cell-Level Table Attributes

• Cell-level attributes affect only the contents of one cell

Page 18: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-18

Spanning Columns

• The colspan attribute lets you create cells that span multiple columns of a table

• Column cells always span to the right

Page 19: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-19

Page 20: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-20

Spanning Rows

• The rowspan attribute lets you create cells that span multiple rows of a table

• Rows always span down

Page 21: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-21

Page 22: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-22

Formatting Tables

Page 23: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-23

Choosing Relative or Fixed Table Widths

• Set relative table widths as percentages in the table width attribute– If you choose relative table widths, your

tables will resize based on the size of the browser window

• Set absolute table widths as pixel values in the table width attribute– Fixed tables remain constant regardless of

the browser window size

Page 24: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-24

Page 25: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-25

Page 26: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-26

Determining the Correct Fixed Width for a Table

• The most common width for page template tables is approximately 975 pixels

• This width supports the 1024 x 768 screen resolution

Page 27: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-27

Page 28: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-28

Adding White Space in a Table

• You can add white space into a table with the cellpadding and cellspacing attributes

Page 29: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-29

Page 30: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-30

Page 31: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-31

Removing Default Table Spacing

• Default spacing values are included in the table even when you don’t specify values for the table’s border, cellpadding, or cellspacing attributes

• Depending on the browser, approximately two pixels are reserved for each of these values

• You can remove the default spacing by explicitly stating a zero value for each attribute

Page 32: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-32

Page 33: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-33

Page 34: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-34

Table Pointers for Well-Designed Tables

Page 35: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-35

Table Pointers for Well-Designed Tables

• Write code that is easy to read• Remove extra white spaces• Center tables to adapt to different resolutions• Stack tables for quicker downloading• Avoid nested tables• Use Cascading Style Sheets for table styles

Page 36: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-36

Removing Extra Spaces• Always remove any leading or trailing spaces

in your table cell content • These spaces cause problems when you try

to join the contents of adjacent cells

Page 37: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-37

Page 38: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-38

Centering Tables

• Centering a fixed table makes it independent of resolution changes, because the table is always centered in the browser window

Page 39: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-39

Page 40: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-40

Stacking Tables

• Because of the way browsers display tables, it is better to build several small tables rather than one large one

• This technique, called stacking tables, also can simplify your table design task, because smaller tables are easier to work with

Page 41: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-41

Page 42: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-42

Avoid Nesting Tables

• Nesting tables is the practice of placing an entire table within a table cell

• Nested tables are not accessible to screen readers and other assistive devices

• This technique is being replaced by newer techniques such as CSS positioning

Page 43: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-43

Page 44: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-44

Creating a Page Template

Page 45: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-45

Creating a Page Template

• In this example you’ll see how to take a design sketch for a Web page and build a template for the page layout

• Figure 5-20 shows a sketch of the desired layout– This layout is designed for a base screen

resolution of 1024 x 768, so the table will be fixed at a width of 975 pixels

Page 46: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-46

Creating a Page Template (continued)

• Notice that the basic structure of the table is three rows by four columns

• Each column uses 25% of the total width of the template

• Row spans and column spans break across the layout to provide visual interest

Page 47: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-47

Page 48: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-48

Building the Basic Table Structure

• Start by building the basic table structure, including all the cells and rows of the table

• As you customize the table you can remove extraneous cells as necessary

• The basic structure is a three-row by four-column table

Page 49: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-49

Page 50: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-50

Setting a Fixed Width

• One of the design characteristics of the template is a fixed width that does not depend on the user’s browser size or screen resolution

• To create this characteristic, use a pixel value in the table width attribute

Page 51: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-51

Page 52: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-52

Creating the Page Banner Cell

• The page banner cell is R1C1• This cell spans the four columns of the table

using the colspan attribute

Page 53: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-53

Page 54: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-54

Creating the Feature Article Cell

• The feature article cell in the layout is R2C2, and spans two columns

• This column span requires the removal of one cell in row two to make room for the span

Page 55: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-55

Page 56: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-56

Creating the Link Column Cells

• The New Link and Linked Ads columns in the layout reside in cells R2C1 and R2C3 respectively

• These cells span rows 2 and 3 of the table• The row spans require the removal of cells

R3C1 and R3C4

Page 57: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-57

Page 58: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-58

Page 59: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-59

Setting the Column Widths

• Column widths must be set in only one cell per column

• It’s also best to set the column widths in only one row of the table

• Setting the column width ensures that the text will wrap properly

Page 60: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-60

Page 61: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-61

Testing the Template

• To verify that your template works properly, populate it with test content

• Test the template in multiple browsers

Page 62: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-62

Page 63: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-63

Page 64: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-64

Page 65: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-65

Page 66: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-66

Page 67: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-67

Examples of Page Templates

• The following templates cover a variety of page layout needs

• You may choose to stack different templates on top of each other for more complex layouts

Page 68: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-68

Page 69: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-69

Page 70: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-70

Page 71: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-71

Page 72: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-72

Page 73: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-73

Page 74: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-74

Summary• Plan your tables by sketching them out first • Use fixed table widths if you want to determine

the size of your page rather than let the browser determine the width

• Use relative widths if you want to build tables that resize with the browser window, wrapping your content to fit

• Write table code that is easy to read, remove extra spaces, and choose whether to center or stack tables

• Avoid using nested tables and use CSS whenever possible to add presentation style to tables

Page 75: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-75

Summary• Work on your pages with the table borders turned on,

which displays the cell boundaries• When you are finished with your layout, you can turn

the borders off• Size your tables based on the page size you want to

create– Use 1024 x 768 as your base screen resolution– In most cases you’ll set the width but not the height of

your tables, allowing the content to flow down the page

Page 76: Chapter 5 Working with Tables

Principles of Web Design, 4th Edition 5-76

Summary

• Test your work!– Table settings, especially cell widths and

heights, can vary based on the user’s browser