HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text,...

45
HTML Tables tMyn 1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables, etc. - into rows and columns of cells. Each table may have an associated caption that provides a short description of the table's purpose. Table rows may be grouped into a head, foot, and body sections, (via the thead, tfoot and tbody elements, respectively). When long tables are printed, the head and foot information may be repeated on each page that contains table data.

Transcript of HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text,...

Page 1: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 1

HTML Tables

• The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables, etc. - into rows and columns of cells.

• Each table may have an associated caption that provides a short description of the table's purpose.

• Table rows may be grouped into a head, foot, and body sections, (via the thead, tfoot and tbody elements, respectively).

• When long tables are printed, the head and foot information may be repeated on each page that contains table data.

Page 2: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 2

• Table cells may either contain "header" information (see the th element) or "data" (see the td element). Cells may span multiple rows and columns.

• You need to know about four basic table tags, as described:

Page 3: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 3

<table>

</table>

The table tag is a container for every other tag used to create a table in HTML. The opening and closing table tags should be placed at the beginning and the end of your table.

<tr>

</tr>

The tr tag stands for table row. The opening and closing tr tags surround the cells for that row.

<th>

</th>

The th tag stands for table header. An optional tag used instead of the td tag, this tag defines a cell containing header information. By default, the content in header cells is bolded and centered.

<td>

</td>

The td tag stands for table data and holds the actual content for the cell. There is an opening and closing td tag for each cell in each row.

Elementary tags for building a HTML Table:

Page 4: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 4

• First table example employs some elementary tags:

Page 5: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 5

Page 6: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 6

• Tables, by nature of their design, have internal and external borders.

• By default, most browsers set the border to zero, making them invisible (see the previous example).

• To make the border visible, use border attribute:

<table border=“3”>

• The larger the number you specify, the thicker the borders become.

• Another useful table attribute might be frame attribute.

Page 7: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 7

• When the borders are visible for a table, it’s easier to see how much space is around the content and in between the cells.

• Two attributes can be added to the table tag:

cellbadding: space between the content within the cell and the edges of that cell.

cellspacing: space in between each of the individual cells.

• Increasing the cell padding can give extra buffer space around the text, so it doesn’t run into the borders.

• Increasing cell spacing allows for a gutter between multiple cells.

Page 8: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 8

• The caption tag enables you to specify captions for your tables.

• This tag is a stand-alone element used after the table tag (see the next example) but before the first table row.

• At times, you might have content in a cell that needs to be kept on a single line. In cases lake this, you can add the nowrap attribute to your td or th tag, which tells the browser to try and keep all the content in that cell on a single line if at all possible.

Page 9: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 9

• Three tags in particular are used to group rows within tables:

thead: table header

tfoot: table footer

tbody: table body

• Using these tags the browser is able to differentiate between the header and footer information, and the main content of the page.

• The header information is repeated at the top of each page or screen view of the table, even if the table is printed.

Page 10: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 10

Page 11: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 11

Page 12: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 12

Page 13: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 13

• We can add the colspan attribute to a td or th tag to merge cells across two or more columns:

Page 14: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 14

Page 15: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 15

Page 16: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 16

• Likewise we can add the rowspan attribute to a td or th tag to merge cells across two or more rows:

Page 17: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 17

Page 18: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 18

Page 19: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 19

Page 20: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 20

• Next example modifies the Nordic countries table by implementing external style sheet:

Page 21: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 21

Page 22: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 22

Page 23: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 23

Page 24: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 24

Page 25: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 25

• Some explanations to the previous example:• white-space: nowrap; This value collapses

whitespace as for 'normal', but suppresses line breaks within text.

• em: the font-size of the relevant font

ex: the ’x-height’ of the relevant font

px: pixels, relative to the viewing device

Page 26: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 26

• The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element.

• The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property can also be used, to change all paddings at once. In that case the order is padding-top, padding-right, padding-

bottom and padding-left,so for example td {padding: 0.25em 0.25em 0.25em 0.25em};

Page 27: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 27

• Now let us talk about using tables to lay out an entire page, regardless of whether it looks like it would fit into a grid or a table structure.

• First example divides text into two columns:

Page 28: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 28

Page 29: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 29

Page 30: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 30

Page 31: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 31

Page 32: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 32

• The table we just dissected didn’t look like the typical table when we first viewed it.

• One of the reasons is this is a seamless table, or one in which the cells are flush up against one another, without borders to separate them.

• To turn a regular table into a seamless table, you must set several attributes in the table tag to 0, to eliminate any extra space around the table cells.

• If we set the border value to 0, that gets us started.

Page 33: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 33

• Next example achieves exactly the same as the previous one but now using the external style sheet:

Page 34: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 34

Page 35: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 35

Page 36: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 36

Page 37: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 37

Page 38: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 38

Page 39: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 39

• The apparent problem with the previous example is that the text starts too near the left border in the first column.

• Let us modify the external style sheet:

Page 40: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 40

Page 41: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 41

Page 42: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 42

Page 43: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 43

Page 44: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 44

Page 45: HTML TablestMyn1 HTML Tables The HTML table model allows authors to arrange data - text, preformatted text, images, links, forms, form fields, other tables,

HTML Tables tMyn 45

• A nested table is one contained within the cell of another table.

• This can be useful when you need to create a completely different table structure in one portion of a page, which cannot be incorporated into the structure of the rest of the page.