Saturday, July 25, 2015

11. HTML Tables

 HTML Tutorial

The HTML tables allow web authors to arrange data like text, images, links, other tables, etc. into rows and columns of cells.
The HTML tables are created using the
tag in which the tag is used to create table rows and tag is used to create data cells.

Example




</span><span class="pln">HTML Tables</span><span class="tag">
border="1"> Row 1, Column 1
Row 1, Column 2 Row 2, Column 1 Row 2, Column 2 This will produce following result:
Row 1, Column 1 Row 1, Column 2
Row 2, Column 1 Row 2, Column 2
Here border is an attribute of
tag and it is used to put a border across all the cells. If you do not need a border then you can use border="0".

Table Heading

Table heading can be defined using tag. This tag will be put to replace
tag, which is used to represent actual data cell. Normally you will put your top row as table heading as shown below, otherwise you can use
element in any row.


Example




</span><span class="pln">HTML Table Header</span><span class="tag">
border="1"> Name
Salary Ramesh Raman 5000 Shabbir Hussein 7000 This will produce following result:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000

Cellpadding and Cellspacing Attributes

There are two attribiutes called cellpadding and cellspacing which you will use to adjust the white space in your table cells. The cellspacing attribute defines the width of the border, while cellpadding represents the distance between cell borders and the content within a cell.

Example




</span><span class="pln">HTML Table Cellpadding</span><span class="tag">
border="1" cellpadding="5" cellspacing="5"> Name
Salary Ramesh Raman 5000 Shabbir Hussein 7000 This will produce following result:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000

Colspan and Rowspan Attributes

You will use colspan attribute if you want to merge two or more columns into a single column. Similar way you will use rowspan if you want to merge two or more rows.

Example




</span><span class="pln">HTML Table Colspan/Rowspan</span><span class="tag">
border="1"> Column 1
Column 2 Column 3
rowspan="2">Row 1 Cell 1
Row 1 Cell 2Row 1 Cell 3 Row 2 Cell 2Row 2 Cell 3 colspan="3">Row 3 Cell 1
This will produce following result:
Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2Row 1 Cell 3
Row 2 Cell 2Row 2 Cell 3
Row 3 Cell 1

Tables Backgrounds

You can set table background using one of the following two ways:
  • bgcolor attribute - You can set background color for whole table or just for one cell.
  • background attribute - You can set background image for whole table or just for one cell.
You can also set border color also using bordercolor attribute.

Example




</span><span class="pln">HTML Table Background</span><span class="tag">
border="1" bordercolor="green" bgcolor="yellow"> Column 1
Column 2 Column 3
rowspan="2">Row 1 Cell 1
Row 1 Cell 2Row 1 Cell 3 Row 2 Cell 2Row 2 Cell 3 colspan="3">Row 3 Cell 1
This will produce following result:
Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2Row 1 Cell 3
Row 2 Cell 2Row 2 Cell 3
Row 3 Cell 1
Here is an example of using background attribute. Here we will use an image available in /images directory.



</span><span class="pln">HTML Table Background</span><span class="tag">
border="1" bordercolor="green" background="/images/test.png"> Column 1
Column 2 Column 3
rowspan="2">Row 1 Cell 1
Row 1 Cell 2Row 1 Cell 3 Row 2 Cell 2Row 2 Cell 3 colspan="3">Row 3 Cell 1
This will produce following result. Here background image did not apply to table's header.
Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2Row 1 Cell 3
Row 2 Cell 2Row 2 Cell 3
Row 3 Cell 1

Table Height and Width

You can set a table width and height using width and height attrubutes. You can specify table width or height in terms of pixels or in terms of percentage of available screen area.

Example




</span><span class="pln">HTML Table Width/Height</span><span class="tag">
border="1" width="400" height="150"> Row 1, Column 1
Row 1, Column 2 Row 2, Column 1 Row 2, Column 2 This will produce following result:
Row 1, Column 1 Row 1, Column 2
Row 2, Column 1 Row 2, Column 2

Table Caption

The caption tag will serve as a title or explanation for the table and it shows up at the top of the table. This tag is depracated in newer version of HTML/XHTML.

Example




</span><span class="pln">HTML Table Caption</span><span class="tag">
border="1" width="100%"> This is the caption
row 1, column 1row 1, columnn 2 row 2, column 1row 2, columnn 2 This will produce following result:
This is the caption
row 1, column 1row 1, columnn 2
row 2, column 1row 2, columnn 2

Table Header, Body, and Footer

Tables can be divided into three portions: a header, a body, and a foot. The head and foot are rather similar to headers and footers in a word-processed document that remain the same for every page, while the body is the main content holder of the table.
The three elements for separating the head, body, and foot of a table are:
  • - to create a separate table header.
  • - to indicate the main body of the table.
  • - to create a separate table footer.
A table may contain several elements to indicate different pages or groups of data. But it is notable that and tags should appear before

Example




</span><span class="pln">HTML Table</span><span class="tag">
border="1" width="100%">
colspan="4">This is the head of the table

colspan="4">This is the foot of the table
Cell 1 Cell 2 Cell 3 Cell 4 This will produce following result:
This is the head of the table
This is the foot of the table
Cell 1 Cell 2 Cell 3 Cell 4

Nested Tables

You can use one table inside another table. Not only tables you can use almost all the tags inside table data tag
.

Example

Following is the example of using another table and other tags inside a table cell.



</span><span class="pln">HTML Table</span><span class="tag">
border="1" width="100%">
border="1" width="100%"> Name
Salary Ramesh Raman 5000 Shabbir Hussein 7000 This will produce following result:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000

0 comments:

Post a Comment

 
Designed by Kakada Akkarak Surakkiat
Technology: របៀប​ដំឡើង Windows 10 នៅ​លើ​កុំព្យូទ័រ!: អ្នកត្រូវដឹងឲ្យ ច្បាស់ពី Windows ដែលអ្នកយក ទៅដំឡើង ដោយសារមាន Windows ខ្លះមានការ crack រួច ឬខ្លះត្រូវការ Product key ភ្លាម និងខ្លះទៀត អាចត្រូវ skip កន្លែងវាយលេខ Product key បាន តែត្រូវ Activate តាមក្រោយ ទើបប្រើប្រាស់បាន។ Technology: ដំណោះ​ស្រាយ Error 80240020 នៅ​ពេល​តម្លើង Windows 10 Free តាម​រយៈ​ការ Upgrade : មាន បញ្ហាមួយចំនួន ទាក់ទងនឹង ការតម្លើង Windows 10 នេះផងដែរ ប៉ុន្តែបញ្ហានោះ កើតឡើង ទៅលើតែកុំព្យូទ័រ មួយចំនួនប៉ុណ្ណោះ គឺខណៈពេល ដែលអ្នក ប្រើប្រាស់ បានទាញយក Windows 10 ចប់ហើយ វាបាន បង្ហាញនូវ ផ្ទាំង error មួយ ដែលមានលេខ សំគាល់ error នោះគឺ 80240020។ ដូចនេះដើម្បី ដោះស្រាយ នូវបញ្ហា មួយនេះ សូមលោកអ្នក តាមដានអាន ជាមួយយើងខ្ញុំ ទាំងអស់គ្នា !!