Top Banner
Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1
35

Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Dec 24, 2015

Download

Documents

Justina Lang
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

1

Tables in HTML

Page 2: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

2

Summary of the previous lecture

• Adding images to web page• Using images as links• Image map• Adding audio and video to web page

Page 3: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

3

Outline

• How to create tables• Page lay-out using tables

Page 4: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

4

1. Creating HTML tables

• Tables display information in rows and columns

• Tables are commonly used to display all manner of data that fits in a grid such as train schedules, television listings, financial reports etc.

Page 5: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

5

1. Creating HTML tables…

• In HTML <table> tag is used to start a table while </table> tag indicates the end of the table

<table>Table Structure</table>

• <tr> tag starts a row of the table and </tr> ends the row

• <td> is used to create a cell inside the row while </td> ends the cell

Page 6: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

6

1. Creating HTML tables…

• The contents of the cell are written between <td> and </td> tags

• <th> tag is used to declare the cell of the heading row of the table

Page 7: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

7

1. Creating HTML tables…

<table border=“1”><tr><td> Name </td><td> Registration No. </td></tr><tr><td>Ali</td><td>FA13-BCS-001</td></tr></table>

Name Registration No.

Ali FA13-BCS-001

Page 8: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

8

1. Creating HTML tables…

Page 9: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

9

1. Creating HTML tables…

Page 10: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

10

1.1 Table Attributes

• Table level attributes• Row level attributes• Cell level attributes

Page 11: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

11

1.1.1 Table Attributes

• The Border Attribute: Indicates the presence of the border around the table

– <table border=“1”>

•The align Attribute: – <table align= “center, right or left”>

•The bgcolor Attribute: sets the background color of the table

– <table bgcolor=“gray”>

•The background Attribute: sets the specified image at the background of the table

– <table background=“image-title”>

Page 12: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

12

1.1.1 Table Attributes…

• The height and width Attributes:• The cellpadding Attribute: The cellpadding

attribute is used to create a gap between the edges of a cell and its contents

– <table cellpadding=“50”>

• The cellspacing Attribute: The cellspacing attribute is used to create a space between the borders of each cell

Page 13: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

13

1.1.1 Table Attributes…

Page 14: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

14

1.1.1 Table Attributes…

Hei

ght

Width

cellpadding

cellspacing

Page 15: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

15

1.1.2 Row level attributes

• The align Attribute: – <tr align=“center,right or left”>

• The bgcolor Attribute:• <tr bgcolor=“gray”>

• The background Attribute:• <tr background=“image-name”>

• The height and width Attributes:• <tr height=“20” widht=“20”>

• The valign Attributes:• <tr valign=“top, middle or bottom”>

Page 16: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

16

1.1.2 Row level attributes…

Page 17: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

17

1.1.2 Row level attributes…

Row

Hei

ght

Vertical Align

Page 18: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

18

1.1.3 Cell level attributes

• The align Attribute: – <td align=“center,right or left”>

• The bgcolor Attribute: • The valign Attributes:• The rowspan Attributes: used when a cell

should span across more than one rows• The colspan Attribute: used when a cell should

span across more than one column

Page 19: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

19

1.1.3 Cell level attributes…<table border=“1”><tr><td rowspan=“2”>Name</td><td colspan=“2”>Subjects</td></tr><tr><td >OOP</td><td >DB</td></tr><tr><td >ALi</td><td >75</td><td >80</td></tr></table>

NameSubjects

ALi 75 80

OOP DB

Page 20: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

20

1.2 Adding caption to the table

• <caption> tag is used to add a caption of the table

• We usually add caption before the first row of the table

Page 21: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

21

1.2 Adding caption to the table…

Page 22: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

22

1.2 Adding caption to the table…

Caption

Page 23: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

23

2. Page Layout using Tables

• We can use tables to define the structure of the web page

Page 24: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

24

2. Page Layout using TablesH

eade

r

Links

Body

Footer

Page 25: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

25

2. Page Layout using Tables…

Example: Step 1 (Structure of the page)

Hea

der

Body and links

Foot

er

Page 26: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

26

2. Page Layout using Tables…

Example: Step 1 (Structure of the page)

Page 27: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

27

2. Page Layout using Tables…

Example: Step 2 (Header section)

Adding Logo

Title

Page 28: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

28

1.5. Page Layout using Tables…

Example: Step 2 (Header section)

Page 29: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

29

2. Page Layout using Tables…

Example: Step 3 (Links section)

Link

s ta

ble

Page 30: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

30

2. Page Layout using Tables…

Example: Step 3 (Links section)

Page 31: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

31

2. Page Layout using Tables…

Example: Step 4 (body section)

Page 32: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

32

2. Page Layout using Tables…

Example: Step 5 (footer section)

Foot

er

Page 33: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

33

2. Page Layout using Tables…

Example: Step 5 (footer section)

Page 34: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan.

34

Summary

• Creating tables in HTML• Table attributes• Page lay-out using tables

Page 35: Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.

Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan.

35

• Chapter 4, Beginning HTML, XHTML,CSS, and JavaScript, by Jon Duckett, Wiley Publishing; 2009, ISBN: 978-0-470-54070-1.

References