B4. Creating Tables
B4. Creating Tables
Creating Tables
Describe
how
to
create
and
format
tables
Explain
the
table
size
and
the
width
of
a
column
Explain
the
process
of
merging
table
cells
Explain
the
page
layout
for
tables
The user can represent the data in a tabular format by using the <table> element in
HTML.
The <tr> element divides the table into rows and the <td> element specifies columns
for each row.
The border attribute of the <table> element specifies a border for making the table
visible in a Web page.
In
this
code,
the
<table>
element
creates
a
table
with
a
border
of
1
pixel.
The
<th>
element
provides
three
column
headings
namely,
Name,
Age,
and
Place.
The
Code
Snippet
demonstrates
how
to
create
a
table
and
span
header
cells
across
two
cells
ver(cally.
<!DOCTYPE HTML>
<html>
<head>
<title>Employee Details</title>
</head>
<body>
<h2>Employee Details</h2>
<table border=”1”>
center:
• Aligns the data within the cell on the center. This is the default value for
table headings.
right:
• Aligns the data within the cell on the right side.
justify:
• Aligns the data within the cell by adjusting the text at the edges.
The
code
aligns
the
data
within
the
row
using
a
style
within
the
<tr>
element.
The
table
content
is
center
aligned
by
seWng
the
value
of
the
text-align
aHribute
to
center.
top:
• Vertically aligns the data within the cell at the top.
middle:
• Vertically aligns the data within the cell at the center.
bottom:
• Vertically aligns the data within the cell at the bottom.
To
set
the
alignment
with
the
style,
you
can
use
the
text-align
aHribute
to
specify
the
ver(cal
alignment
use
the
following
syntax:
Syntax:
<td style= “text align: center; vertical align: middle”>
Aptech Web site </a>
The
text-align
aHribute
is
set
to
the
value
center,
which
specifies
that
the
data
within
the
rows
are
centrally
aligned.
The
vertical-align
is
used
to
specify
the
ver(cal
alignment
in
the
table.
Ø Padding
Padding
is
the
amount
of
space
between
the
content
and
its
outer
edge.
For
tables,
padding
is
referred
as
a
space
between
the
text
and
the
cell
border.
Suppose,
if
the
user
wants
to
set
the
padding
aHribute
for
the
individual
cells
then
padding
aHribute
can
be
used
in
a
style
as
follows:
<td style=”padding: 4px”>
The
code
creates
a
table
having
a
border
of
1
pixel,
table
with
five
columns
and
five
rows,
and
uses
the
colspan
and
rowspan
aHributes
respec(vely.
Following
figure
displays
the
merging
table
cells.
border-width:
• Used to control the thickness of the border and the values are specified in
pixels.
border-color:
• Used to control the color of the border and specifies the color by either
name, or RGB value, or hexadecimal number.
border-style:
• Used to control the line style. Users can choose between solid, dashed,
groove, dotted, outset, ridge, inset, or none.
To format the sides of the border individually, replace the border attribute with border-
bottom, border-top, border-right, or border-left attribute.
The user can apply these attributes to the entire table or individual cells and also create
rules in the <style> area.
<!DOCTYPE HTML>
<html>
<head>
<title>Page Layout </title>
</head>
<style>
The
code
creates
a
page
layout
for
a
Web
site.
The
data
is
arranged
in
a
tabular
format
and
an
embedded
style
is
used
for
defining
the
style.
The
style
is
defined
using
the
style
element
placed
immediately
a\er
the
<head>
sec(on.
Defining
a
style
in
this
manner
helps
to
reuse
the
style
in
the
same
Web
page.
Padding
is
the
amount
of
space
between
the
content
and
its
outer
edge.
The
cap(on
element
defines
a
cap(on
for
a
table.
It
is
a
sub-‐element
of
the
<table>
element.
Spanning
refers
to
a
process
of
extending
a
cell
across
mul(ple
rows
or
columns.
The
rowspan
aHribute
spans
a
data
cell
across
two
or
more
rows.
The
colspan
aHribute
allows
the
user
to
specify
the
number
of
columns
a
cell
should
span.
The
border
aHribute
of
the
table
element
allows
the
user
to
specify
a
border
for
making
the
table
visible
in
a
Web
page.
Tables
allow
the
user
to
organize
the
data.
It
enables
the
developer
to
design
a
Web
page
having
an
aHrac(ve
page
layout.
©
Aptech
Ltd.
Crea(ng
Tables
/
Session
9
39