Html table tags

Post on 22-Nov-2014

1.641 views 2 download

description

HTML Table Tags - This tag is used to create and design tables.

Transcript of Html table tags

www.eshikshak.co.in

�� Tables are very useful to arrange in HTML Tables are very useful to arrange in HTML and they are used very frequently by almost all and they are used very frequently by almost all web developersweb developers..

�� Tables are just like spreadsheets and they are Tables are just like spreadsheets and they are made up of rows and columnsmade up of rows and columns..

�� Create Create a table in HTML/XHTML by using a table in HTML/XHTML by using <table> tag.<table> tag.

www.eshikshak.co.in

www.eshikshak.co.in

�� Table heading can be defined using <th> Table heading can be defined using <th> element.element.

�� This tag will be put to replace <td> tag which This tag will be put to replace <td> tag which is used to represent actual data.is used to represent actual data.

www.eshikshak.co.in

www.eshikshak.co.in

�� There are two attributes called There are two attributes called cell paddingcell padding and and cell spacingcell spacing which you will use to adjust which you will use to adjust the white space in your table cell..the white space in your table cell..

�� Cell spacing defines the width of the border.Cell spacing defines the width of the border.�� While cell padding represents the distance While cell padding represents the distance

between cell borders and the content within.between cell borders and the content within.

www.eshikshak.co.in

<table border="1" cellpadding="5" cellspacing="5"><tr><th>Name</th><th>Salary</th></tr><tr><td>Prakash Khaire</td><td>5000</td></tr><tr><td>Hardik Vyas</td><td>7000</td></tr></table>

Name Salary

Ramesh Raman 5000

Shabbir Hussein 7000

www.eshikshak.co.in

�� Use Use colspancolspan attribute if you want to merge attribute if you want to merge two or more columns into a single column.two or more columns into a single column.

�� Use Use rowspanrowspan if you want to merge two or if you want to merge two or more rows.more rows.

www.eshikshak.co.in

<table border="1"><tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr><tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr><tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr><tr><td colspan="3">Row 3 Cell 1</td></tr></table>

Column 1 Column 2 Column 3Row 1 Cell 1

Row 1 Cell 2

Row 1 Cell 3Row 2 Cell

2Row 2 Cell 3Row 3 Cell 1

www.eshikshak.co.in

�� Set table background using of the following Set table background using of the following two ways:two ways: Using Using bgcolorbgcolor attribute - You can set background attribute - You can set background

color for whole table or just for one cell.color for whole table or just for one cell. Using Using backgroundbackground attribute - You can set attribute - You can set

background image for whole table or just for one background image for whole table or just for one cell.cell.

www.eshikshak.co.in

<table border="5" bordercolor="green" bgcolor="gray"><tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr><tr><td rowspan="2">Row 1 Cell 1</td><td bgcolor="red">Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr><tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr><tr><td colspan="3">Row 3 Cell 1</td></tr></table>

Column 1 Column 2 Column 3Row 1 Cell 1 Row 1 Cell 2 Row 1 Cell 3

Row 2 Cell 2 Row 2 Cell 3Row 3 Cell 1

www.eshikshak.co.in

�� set a table width and height using set a table width and height using widthwidth and and heightheight attributes. attributes.

�� You can specify table width or height in terms You can specify table width or height in terms of integer value or in terms of percentage of of integer value or in terms of percentage of available screen area. available screen area.

www.eshikshak.co.in

<table border="1" width="400" height="150"><tr><td>Row 1, Column 1</td><td>Row 1, Column 2</td></tr><tr><td>Row 2, Column 1</td><td>Row 2, Column 2</td></tr></table>

Row 1, Column 1 Row 1, Column 2Row 2, Column 1 Row 2, Column 2

www.eshikshak.co.in

�� The The captioncaption tags will serve as a title or tags will serve as a title or explanation and show up at the top of the explanation and show up at the top of the table. table.

<table border="1"><caption>This is the caption</caption><tr><td>row 1, column 1</td><td>row 1, columnn 2</td></tr></table>

This is the captionrow 1, column 1

row 1, columnn 2

www.eshikshak.co.in

�� Tables can be divided into three portions: Tables can be divided into three portions: a headera header a bodya body a foota foot

�� The head and foot are rather similar to headers The head and foot are rather similar to headers and footers in a word-processed document that and footers in a word-processed document that remain the same for every page, while the remain the same for every page, while the body is the main content of the table.body is the main content of the table.

www.eshikshak.co.in

�� The three elements for separating the head, The three elements for separating the head, body, and foot of a table are:body, and foot of a table are: <thead> - <thead> - to create a separate table header.to create a separate table header. <tbody> - <tbody> - to indicate the main body of the table.to indicate the main body of the table. <tfoot> - <tfoot> - to create a separate table footer.to create a separate table footer.

www.eshikshak.co.in

<table border="1" width="100%"><thead><tr><td colspan="4">This is the head of the table</td></tr></thead><tfoot><tr><td colspan="4">This is the foot of the table</td></tr></tfoot><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr><tr>...more rows here containing four cells...</tr></tbody><tbody><tr><td>Cell 1</td><td>Cell 2</td></tr><tr>...more rows here containing four cells...</tr></tbody></table>

www.eshikshak.co.in

This is the head of the tableThis is the foot of the tableCell 1 Cell 2...more rows here containing four cells... Cell 1 Cell 2...more rows here containing four cells...

www.eshikshak.co.in