Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Basics
HTML, Text, Images, Tables
A.Kalyan
Kumar
Asst.Profe
ssor
Table of Contents
1.
Introduction to HTML
HTML in Details
HTML in Details
The <body> Section
Text Styling and Formatting Tags
Hyperlinks: <a>, Hyperlinks and
Sections
Images: <img>
Lists: <ol>, <ul> and <dl>
3.
4.
5.
Client running
a Web
Browser
Server running
Web Server
Software (IIS,
Apache, etc.) 4
Microsoft FrontPage
Macromedia Dreamweaver
Netscape Composer
Microsoft Word
6
HTML Basics
Text, Images, Tables,
Forms
HTML Structure
some-tags.html
<!DOCTYPE HTML>
<html>
<head>
<title>Simple Tags Demo</title>
</head>
<body>
<a href="http://www.telerik.com/" title=
"Telerik site">This is a link.</a>
<br />
<img src="logo.gif" alt="logo" />
<br />
<strong>Bold</strong> and <em>italic</em> text.
</body>
</html>
11
Tags Attributes
Headings and
Paragraphs
Paragraph Tags
<p>This is my first paragraph</p>
<p>This is my second paragraph</p>
Headings and
Paragraphs
Example
headings.html
<!DOCTYPE HTML>
<html>
<head><title>Headings and
paragraphs</title></head>
<body>
<h1>Heading 1</h1>
<h2>Sub heading 2</h2>
<h3>Sub heading 3</h3>
<p>This is my first paragraph</p>
<p>This is my second paragraph</p>
<div style="background:skyblue">
This is a div</div>
</body>
</html>
14
Headings and
Paragraphs Example
headings.html
(2)
<!DOCTYPE HTML>
<html>
<head><title>Headings and
paragraphs</title></head>
<body>
<h1>Heading 1</h1>
<h2>Sub heading 2</h2>
<h3>Sub heading 3</h3>
<p>This is my first paragraph</p>
<p>This is my second paragraph</p>
<div style="background:skyblue">
This is a div</div>
</body>
</html>
15
The <!DOCTYPE>
Declaration
HTML documents must start with a
document type definition (DTD)
It tells web browsers what type is the
served code
Possible versions: HTML 4.01, XHTML
1.0 (Transitional or Strict), XHTML 1.1,
HTML 5
Example:
<!DOCTYPE html PUBLIC
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
See
http://w3.org/QA/2002/04/valid-dtd-list.html
16
<input type="checkbox"
checked="checked" />
18
<meta>
<script>
19
<head> Section:
<title> tag
20
<head> Section:
<meta>
<head> Section:
<script>
22
scripts-
<html>
example.html
<head>
<title>JavaScript Example</title>
<script type="text/javascript">
function sayHello() {
document.write("<p>Hello World!
<\/p>");
}
</script>
</head>
<body>
<script type=
"text/javascript">
sayHello();
</script>
</body>
</html>
23
<body> Section:
Introduction
The <body> section describes the
viewable portion of the page
Starts after the <head> </head>
section
Begins with <body> and ends with
<html>
</body>
<head><title>Test page</title></head>
<body>
<!-- This is the Web page body -->
</body>
</html>
24
Text Formatting
italicized
<u></u>
underlined
<sup></sup>
Samplesuperscript
<sub></sub>
Samplesubscript
<strong></strong>
strong
<em></em>
emphasized
Preformatted text
<pre></pre>
25
text-
Text Formatting
Example
26
text-
Text Formatting
Example (2)
27
Hyperlinks and
Sections
Hyperlinks Example
hyperlinks.html
<a href="form.html">Fill Our Form</a> <br />
<a href="../parent.html">Parent</a> <br />
<a href="stuff/cat.html">Catalog</a> <br />
<a href="http://www.devbg.org"
target="_blank">BASD</a> <br />
<a href="mailto:bugs@example.com?subject=Bug
Report">Please report bugs here (by e-mail
only)</a>
<br />
<a href="apply-now.html"><img src="apply-nowbutton.jpg /></a> <br />
<a href="../english/index.html">Switch to English
version</a> <br />
32
Hyperlinks Example
(2)
hyperlinks.html
<a href="form.html">Fill Our Form</a> <br />
<a href="../parent.html">Parent</a> <br />
<a href="stuff/cat.html">Catalog</a> <br />
<a href="http://www.devbg.org"
target="_blank">BASD</a> <br />
<a href="mailto:bugs@example.com?subject=Bug
Report">Please report bugs here (by e-mail
only)</a>
<br />
<a href="apply-now.html"><img src="apply-nowbutton.jpg /></a> <br />
<a href="../english/index.html">Switch to English
version</a> <br />
33
Image attributes:
src
alt
height
width
border
Example:
<img src="./php.png" alt="PHP Logo" />
34
Miscellaneous Tags
<center></center>: Deprecated!
<font></font>: Deprecated!
<center>Hello World!</center>
35
Miscellaneous Tags
Example
misc.html
<html>
<head>
<title>Miscellaneous Tags Example</title>
</head>
<body>
<hr size="5" width="70%" />
<center>Hello World!</center>
<font size="3" color="blue">Font3</font>
<font size="+4" color="blue">Font+4</font>
</body>
</html>
36
2. Orange
3. Grapefruit
a.
b.
A. Apple
B. Orange c.
C. Grapefruit
ii. Orange
iii. Grapefruit
Apple
Orange I. Apple
GrapefruitII. Orange
III. Grapefruit
37
Apple
Orange
Pear
o Apple
Apple
Orange
Orange
Pear
Pear
38
39
Lists Example
<ol type="1">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ol>
lists.html
<ul type="disc">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ul>
<dl>
<dt>HTML</dt>
<dd>A markup lang</dd>
</dl>
40
HTML Special
Characters
HTML
Symbol Name
Entity
Copyright Sign
Registered Trademark
Sign
Trademark Sign
©
™
Less Than
<
Greater Than
>
Ampersand
&
Non-breaking Space
Em Dash
—
Quotation Mark
"
Euro
€
British Pound
£
Japanese Yen
¥
®
Symbol
<
>
&
"
41
Special Characters
Example
<p>[>> Welcome
special <<]</p>
<p>►I have following cards:chars.html
A♣, K♦ and 9♥.</p>
<p>►I prefer hard rock ♫
music ♫</p>
<p>© 2006 by Svetlin Nakov & his
team</p>
<p>Telerik Academy</p>
42
43
HTML Tables
HTML Tables
46
47
code, it is
49
Nested Tables
nestedtables.html
50
cell
cell
cell
cell
cell
cell
cell
cell
Defines the
empty space
between
cells
Defines the
empty space
around the cell
content
51
table<html>
cells.html
<head><title>Table Cells</title></head>
<body>
<table cellspacing="15" cellpadding="0">
<tr><td>First</td>
<td>Second</td></tr>
</table>
<br/>
<table cellspacing="0" cellpadding="10">
<tr><td>First</td><td>Second</td></tr>
</table>
</body>
</html>
52
table<html>
cells.html
<head><title>Table Cells</title></head>
<body>
<table cellspacing="15" cellpadding="0">
<tr><td>First</td>
<td>Second</td></tr>
</table>
<br/>
<table cellspacing="0" cellpadding="10">
<tr><td>First</td><td>Second</td></tr>
</table>
</body>
</html>
53
colspan=
"1"
cell[1,
2]
cell[2,1]
colspan=
Defines how
"2"
many
columns the
cell occupies
rowspan
="2"
cell[1,1]
rowspan
="1"
cell[1
,2]
cell[2
,1]
rowspan
Defines
how
="1"
many rows
the cell
occupies
54
table-colspan-rowspan.html
<table cellspacing="0">
<tr class="1"><td>Cell[1,1]</td>
<td colspan="2">Cell[2,1]</td></tr>
<tr class=2"><td>Cell[1,2]</td>
<td rowspan="2">Cell[2,2]</td>
<td>Cell[3,2]</td></tr>
<tr class=3"><td>Cell[1,3]</td>
<td>Cell[2,3]</td></tr>
</table>
55
Cell[1,2
]
Cell[1,3
]
Cell[2,2
]
Cell[3,2
]
Cell[2,3
]
56
HTML
Forms
Entering User Data from a
Web Page
HTML Forms
Example:
Form Fields
Fieldsets
60
Labels
61
62
63
HTML Frames
<frameset>, <frame> and <iframe>
HTML Frames
Frames provide a way to show
multiple HTML documents in a
single Web page
The page can be split into separate
views (frames) horizontally and
vertically
Frames were popular in the early
ages of HTML development, but
now their usage is rejected
Frames are not supported by all
user agents (browsers, search
65
frames.ht
ml
<head><title>Frames Example</title></head>
<frameset cols="180px,*,150px">
<frame src="left.html" />
<frame src="middle.html" />
<frame src="right.html" />
</frameset>
</html>
66
<iframe name="iframeGoogle"
height="400" src="http://www.google.com"
frameborder="yes" scrolling="yes"></iframe>
67
Cascading Style
Sheets (CSS)
Table of Contents
What is CSS?
Styling with Cascading Stylesheets
(CSS)
Selectors and style definitions
Linking HTML and CSS
Fonts, Backgrounds, Borders
The Box Model
Alignment, Z-Index, Margin,
Padding
Positioning and Floating Elements
69
Vestibulum et odio et
ipsum
accumsan accumsan.
Morbi at
Presentation
(CSS Document)
Bold
Italics
Indent
70
71
CSS
Intro
Styling with Cascading
Stylesheets
CSS Introduction
73
On-screen
In print
Handheld, projection, etc.
even by voice or Braille-based
reader
74
Why Cascading?
75
76
and text-decoration
77
http://css.maxdesign.co
m.au/
bold; }
78
Selectors
Examples:
.header a { color:
green }
Selectors (2)
By element id:
#element_id { color: #ff0000; }
80
Selectors (3)
81
Selectors (4)
82
Selectors (5)
84
87
CSS Cascade
(Precedence)
90
CSS Specificity
Embedded Styles
92
Embedded Styles:
Example
embeddedstylesheets.html
<!DOCTYPE html PUBLIC
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Style Sheets</title>
<style type="text/css">
em {background-color:#8000FF;
color:white}
h1 {font-family:Arial, sans-serif}
p {font-size:18pt}
.blue {color:blue}
</style>
<head>
93
Embedded Styles:
Example (2)
<body>
<h1 class="blue">A Heading</h1>
<p>Here is some text. Here is some text.
Here
is some text. Here is some text. Here is
some
text.</p>
<h1>Another Heading</h1>
<p class="blue">Here is some more text.
Here is some more text.</p>
<p class="blue">Here is some <em>more</em>
text. Here is some more text.</p>
</body>
</html>
94
Embedded Styles:
Example (3)
<body>
<h1 class="blue">A Heading</h1>
<p>Here is some text. Here is some text.
Here
is some text. Here is some text. Here is
some
text.</p>
<h1>Another Heading</h1>
<p class="blue">Here is some more text.
Here is some more text.</p>
<p class="blue">Here is some <em>more</em>
text. Here is some more text.</p>
</body>
</html>
95
External linking
Separate pages can all use a shared
style sheet
Only modify a single file to change the
styles across your entire Web site (see
http://www.csszengarden.com/)
96
External Styles:
Example
styles.css
/* CSS Document */
a
{ text-decoration: none }
{ color: red;
font-weight: bold }
{ margin-left: 2cm }
ul ul
{ text-decoration: underline;
margin-left: .5cm }
98
External Styles:
Example (2)
externalstyles.html
<!DOCTYPE
html
99
External Styles:
Example (3)
<li>Bread
<ul>
<li>White bread</li>
<li>Rye bread</li>
<li>Whole wheat bread</li>
</ul>
</li>
<li>Rice</li>
<li>Potatoes</li>
<li>Pizza <em>with mushrooms</em></li>
</ul>
<a href="http://food.com" title="grocery
store">Go to the Grocery store</a>
</body>
</html>
100
External Styles:
Example (4)
<li>Bread
<ul>
<li>White bread</li>
<li>Rye bread</li>
<li>Whole wheat bread</li>
</ul>
</li>
<li>Rice</li>
<li>Potatoes</li>
<li>Pizza <em>with mushrooms</em></li>
</ul>
<a href="http://food.com" title="grocery
store">Go to the Grocery store</a>
</body>
</html>
101
Text-related CSS
Properties
102
font
Shorthand Font
Property
Backgrounds
background-image
URL of image to be used as
background, e.g.:
background-image:url("back.gif");
background-color
Using color and image and the same
time
background-repeat
repeat-x, repeat-y, repeat, norepeat
background-attachment
105
Backgrounds (2)
background-position: specifies
vertical and horizontal position of
the background image
Vertical position: top, center, bottom
Horizontal position: left, center,
right
Both can be specified in percentage
or other numerical values
Examples:
background-position: top left;
background-position: -5px 50%;
106
Background Shorthand
Property
is
equal to writing:
background-color:
#FFF0C0;
background-image: url("back.gif");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: top;
107
Background-image or
<img>?
Borders
border-width: thin, medium, thick or
numerical value (e.g. 10px)
border-color: color alias or RGB
value
border-style: none, hidden, dotted,
dashed, solid, double, groove, ridge,
inset, outset
Each property can be defined
separately for left, top, bottom and
right
border-top-style, border-left-
109
Border Shorthand
Property
is equal to writing:
border-width:1px;
border-color:red;
border-style:solid;
110
margin: 5px;
Sets all four sides to have margin of
5 px;
113
114
IE Quirks Mode
When using
quirks mode
(pages with no
DOCTYPE or
with a HTML 4
Transitional
DOCTYPE),
Internet
Explorer
violates the box
model standard
115
Positioning
position: defines the positioning of
the element in the page content
flow
The value is one of:
static (default)
relative relative position according
to where the element would appear
with static position
absolute position according to the
innermost positioned parent element
fixed same as absolute, but ignores
page scrolling
116
Positioning (2)
Margin VS relative positioning
Fixed and absolutely positioned
elements do not influence the page
normal flow and usually stay on top
of other elements
117
Positioning (3)
top, left, bottom, right: specifies
offset of absolute/fixed/relative
positioned element as numerical
values
z-index : specifies the stack level
of positioned elements
118
Inline element
positioning
119
Float
Float (2)
121
Clear
clear
Clear (2)
123
Opacity
Visibility
visibility
Determines whether the element is
visible
hidden: element is not rendered, but
still occupies place on the page
(similar to opacity:0)
visible: element is rendered
normally
125
Display
Display (2)
127
Overflow
129
130
Maintenance Example
Title
Title
Title
Some random
Some random
text here.
text here.
Some random
You cant read
You cant read
text here.
Title
Title
Some random
it anyway!
it anyway!
You
cant
read
text here.
Title
Title
Some random
Some random
Har har har!
Har har har!
it anyway!
You cant read
text
here.
text
here.
Some random
Some random
Use Css.
Use Css.
Har har har!
it anyway!
You
cant
read
You
cant
read
text here.
text here.
Title
Use Css.
Har har har!
it anyway!
it anyway!
You cant read
You cant read
Title
Use Css.
Some random
Har har har!
Har har har!Title
it anyway!
it anyway!
text here.
Use Css.
Some random
Use Css.
Some random
Har har har!
Har har har!
You cant read
text here.
text here.
Title
Use Css.
Use Css.
it anyway!
You cant read
You cant read
Title
Some random
Har har har!
it anyway!
it anyway!
text here.
Title
Title
Title
Some random
Use Css.
Har har har!
Har har har!
Title
You cant read
text here.
Some random Some random
Use Css.
Some random
Use Css.
it anyway!
You cant read
Some random
text here.
text here.
text here.
Title
Har har har!
it anyway!
text here.
You cant read You cant read
You cant read
Title
Some random
Use Css.
Har har har!
You cant read
it anyway!
it anyway!
it anyway!
text
here.
Title
Use Css.
Some random
it anyway!
Har har har! Har har har!
Har har har!
You
cant
read
text here.
Title
Har har har! Title Use Css.
Use Css.
Some random
Use Css.
it anyway!
You cant read
Use Css.
text here.
Title
Some random
Some random
Har har har!
it anyway!
You cant read
text here.
text here.
Some random Use Css.
Har har har!
it anyway!
You cant read
You cant read
text here.
Use Css.
Har har har!
it anyway!
it anyway!
You
cant
read
Title
Title
Use Css.
Har har har!
Har har
har!
it anyway!
Use Css.
Use Css.
Some random
Some random
Har har har!
text here.
text here.
Title
Title
Use Css.
You cant read
You cant read
Title
Some random
Some random
it anyway!
it anyway!
text here.
text here.
Title
Title
Some random
Har har har!
Har har har! Title
You cant read
You cant read
text here.
Use Css.
Some random
Some random Use Css.
Some random
it anyway!
it anyway!
You cant read
text here.
text here.
text here.
Title
Har har har!
Har har har!
it anyway!
You cant read
You cant read
You cant read
Use Css.
Some random
Use Css.
Har har har!
it anyway!
it anyway!
it anyway!
text here. Title
Use Css.
Har har har!
Har har har!
Har har har! Title
You cant read
Some random
Use Css.
Use Css.
Use Css.
Some random
it anyway!
text here.
text here.
Title
Title
Title
Har har har!
You cant read
You cant read
Some random Use Css.
Some random
Some random
it anyway!
it anyway!
text here.
text here.
text here.
Title
Har har har!
Har har har!
You cant read
You cant read
You cant read
Some random
Use Css.
Use Css.
it anyway!
it anyway!
it anyway!
text here.
Title
Title
Har har har!
Har har har!
Har har har!Title
You cant read
Title
Title
Title
Some random
Use Css.
Some random
Use Css.
Use Css.
Some random
it anyway!
text here.
text here.
text here.
Some random
Some random
Some random
Har har har!
You cant read
You cant read
You cant read
text
here.
text
here.
text here.
Title
Use Css.
it anyway!
it anyway!
it anyway!
You cant read
You cant read
You cant read
Some random
Har har har!
Har
har
har!
Har
har
har!
it anyway!
it anyway!
it anyway!
text
here.
Use Css.
Use Css.
Use Css.
Har har har!
Har har har!
Har har har!
You
cant
read
Title
Title
Use Css.
Use Css.
Use Css.
it anyway!
Title
Title
Some random
Some random
Har har har!
text here.
text here.
Some random
Some random
Use Css.
You cant read
You cant read
text here.
text here.
Title
it anyway!
it anyway!
You cant read
You cant read
Title
Some random
Har har har!
Har har har!
it anyway!
it anyway!
text here.Title
Use Css.
Use Css.
Some random
Har har har!
Har har har!
You cant read
text here.
Title
Title Use Css.
Some random
Use Css.
it anyway!
You cant read
text here.
Title
Some random
Some random
Har har har!
it anyway!
You cant read
text here.
text here.
Use Css.
Some random
Har har har!
it anyway!
You cant read
You cant read
text here.
Title
Title
Use Css.
Har har har!
it anyway!
it anyway!
You cant read
Use Css.
Some random Har har har!
Some random
Har har har!
it anyway!
text here.
text
here.
Title
Title
Use Css.
Use Css.
Har har har!
You cant read
You cant read
Some random
Some random
Use Css.
it anyway!
it anyway!
text here.
text here.
Har har har!
Har har har!
You cant read
You cant read
Use Css.
Use Css.
it anyway!
it anyway!
Har har har!
Har har har!
Use Css.
Use Css.
Title
CS
S
file
131
132
133
134
Introduction to
JavaScript
Table of Contents
What is DHTML?
DHTML Technologies
XHTML, CSS, JavaScript, DOM
136
What is JavaScript
Implementing JavaScript into Web
pages
In <head> part
In <body> part
In external .js file
137
JavaScript Syntax
JavaScript operators
JavaScript Data Types
JavaScript Pop-up boxes
alert, confirm and prompt
138
DHTML
Dynamic Behavior at the Client Side
What is DHTML?
CSS
JavaScri
pt
DOM
140
141
JavaScript
JavaScript
Client-side technology
Embedded in your HTML page
Interpreted by the Web browser
143
JavaScript Advantages
144
145
146
147
Highly recommended
148
JavaScript When is
Executed?
/>
onclick="alert('clicked!')"
Executed when the event
is fired by
149
Calling a JavaScript
Function from Event
Handler Example
<html>
image<head>
onclick.html
<script type="text/javascript">
function test (message) {
alert(message);
}
</script>
</head>
<body>
<img src="logo.gif"
onclick="test('clicked!')" />
</body>
</html>
150
<html>
external<head>
JavaScript.html
<script src="sample.js" type="text/javascript">
</script>
</head>
The <script> tag is
<body>
always empty.
<button onclick="sample()" value="Call
JavaScript
function from sample.js" />
</body>
External
JavaScript file:
</html>
function sample() {
alert('Hello from sample.js!')
}
sample.j
s
151
The
JavaScript
Syntax
JavaScript Syntax
153
Data Types
Arrays
Everything is Object
155
String Operations
What is "9" + 9?
alert("9" + 9);
// fat cats
// 99
// 18
156
Appending
an element / getting the
arr.push(3);
var element
= arr.pop();
last
element:
arr.length;
Reading
Confirmation box
Contains text, [OK] button and
[Cancel]
button:
confirm("Are
you sure?");
Prompt box
Contains text, input field with
prompt ("enter amount", 10);
default value:
158
sum-ofnumbers.html
<html>
Sum of Numbers
Example
<head>
<title>JavaScript Demo</title>
<script type="text/javascript">
function calcSum() {
value1 =
parseInt(document.mainForm.textBox1.value);
value2 =
parseInt(document.mainForm.textBox2.value);
sum = value1 + value2;
document.mainForm.textBoxSum.value = sum;
}
</script>
</head>
159
Sum of Numbers
Example (2)
sum-of-numbers.html
(cont.)
<body>
<form name="mainForm">
<input type="text" name="textBox1" />
<br/>
<input type="text" name="textBox2" />
<br/>
<input type="button" value="Process"
onclick="javascript: calcSum()" />
<input type="text" name="textBoxSum"
readonly="readonly"/>
</form>
</body>
</html>
160
JavaScript Prompt
Example
prompt.ht
ml
price = prompt("Enter
the price",
"10.00");
alert('Price + VAT = ' + price * 1.2);
161
Conditional Statement
(if)
unitPrice = 1.30;
if (quantity > 100) {
unitPrice = 1.20;
}
Symb
>
ol
Meaning
Greater than
<
Less than
>=
==
Greater than or
equal to
Less than or equal
to
Equal
!=
Not equal
<=
162
Conditional Statement
(if) (2)
conditional-statements.html
var a = 0;
var b = true;
if (typeof(a)=="undefined" ||
typeof(b)=="undefined") {
document.write("Variable a or b is undefined.");
}
else if (!a && b) {
document.write("a==0; b==true;");
} else {
document.write("a==" + a + "; b==" + b + ";");
}
163
Switch Statement
Loops
Like in C#
for loop
while loop
do while loop
var counter;
for (counter=0; counter<4; counter++) {
alert(counter);
}
while (counter < 5) {
alert(++counter);
}
loops.html
165
Functions
Code structure splitting code into
parts
Data comes in, processed, result
returned
Parameters
function average(a, b,
c)
{
var total;
total = a+b+c;
return total/3;
}
come in here.
Declaring
variables is
optional. Type
is never
declared.
Value
returned here.
166