SlideShare a Scribd company logo
HTML Basics
HTML, Text, Images, Tables
Table of Contents
ยฉ Sun Technologies Inc. 2
1. Introduction to HTML
How the Web Works?
What is a Web Page?
My First HTML Page
Basic Tags: Hyperlinks, Images, Formatting
Headings and Paragraphs
2. HTML in Details
The <!DOCTYPE> Declaration
The <head> Section: Title, Meta, Script, Style
Table of Contents (2)
ยฉ Sun Technologies Inc. 3
2. HTML in Details
โ€ข The <body> Section
โ€ข Text Styling and Formatting Tags
โ€ข Hyperlinks: <a>, Hyperlinks and Sections
โ€ข Images: <img>
โ€ข Lists: <ol>, <ul> and <dl>
3. The <div> and <span> elements
4. HTML Tables
5. HTML Forms
How the Web Works?
โ€ข WWW use classical client / server architecture
โ€ข HTTP is text-based request-response protocol
4
Page request
Client running a
Web Browser
Server running
Web Server
Software (IIS,
Apache, etc.)
Server response
HTTP
HTTP
ยฉ Sun Technologies Inc.
What is a Web Page?
โ€ข Web pages are text files containing HTML
โ€ข HTML โ€“ Hyper Text Markup Language
โ€ข A notation for describing
โ€ข document structure (semantic markup)
โ€ข formatting (presentation markup)
โ€ข The markup tags provide information about the page content
structure
5ยฉ Sun Technologies Inc.
Creating HTML Pages
โ€ข An HTML file must have an .htm or .html file extension
โ€ข HTML files can be created with text editors:
โ€ข NotePad, NotePad ++, PSPad
โ€ข Or HTML editors (WYSIWYG Editors):
โ€ข Microsoft FrontPage
โ€ข Macromedia Dreamweaver
โ€ข Netscape Composer
โ€ข Microsoft Word
โ€ข Visual Studio
6ยฉ Sun Technologies Inc.
HTML Basics
Text, Images, Tables, Forms
HTML Structure
โ€ขHTML is comprised of โ€œelementsโ€ and โ€œtagsโ€
โ€ขBegins with <html> and ends with </html>
โ€ขElements (tags) are nested one inside another:
โ€ขTags have attributes:
โ€ขHTML describes structure using two main sections:
<head> and <body>
8
<html> <head></head> <body></body> </html>
<img src="logo.jpg" alt="logo" />
ยฉ Sun Technologies Inc.
HTML Code Formatting
โ€ขThe HTML source code should be formatted to
increase readability and facilitate debugging.
โ€ขEvery block element should start on a new line.
โ€ขEvery nested (block) element should be indented.
โ€ขBrowsers ignore multiple whitespaces in the page
source, so formatting is harmless.
โ€ข For performance reasons, formatting can be sacrificed
ยฉ Sun Technologies Inc. 9
First HTML Page
10
<!DOCTYPE HTML>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<p>This is some text...</p>
</body>
</html>
test.html
ยฉ Sun Technologies Inc.
<!DOCTYPE HTML>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<p>This is some text...</p>
</body>
</html>
First HTML Page: Tags
11
Opening
tag
Closing
tag
An HTML element consists of an opening tag, a closing
tag and the content inside.
ยฉ Sun Technologies Inc.
<!DOCTYPE HTML>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<p>This is some text...</p>
</body>
</html>
First HTML Page: Header
12
HTML
header
ยฉ Sun Technologies Inc.
<!DOCTYPE HTML>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<p>This is some text...</p>
</body>
</html>
First HTML Page: Body
ยฉ Sun Technologies Inc.
13
HTML body
Some Simple Tags
โ€ข Hyperlink Tags
โ€ข Image Tags
โ€ข Text formatting tags
ยฉ Sun Technologies Inc. 14
<a href="http://www.telerik.com/"
title="Telerik">Link to Telerik Web site</a>
<img src="logo.gif" alt="logo" />
This text is <em>emphasized.</em>
<br />new line<br />
This one is <strong>more emphasized.</strong>
Some Simple Tags โ€“ Example
ยฉ Sun Technologies Inc. 15
<!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>
some-tags.html
Some Simple Tags โ€“ Example (2)
16
<!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>
some-tags.html
ยฉ Sun Technologies Inc.
Tags Attributes
โ€ข Tags can have attributes
โ€ข Attributes specify properties and behavior
โ€ข Example:
โ€ข Few attributes can apply to every element:
โ€ข id, style, class, title
โ€ข The id is unique in the document
โ€ข Content of title attribute is displayed as hint when the element is hovered with the mouse
โ€ข Some elements have obligatory attributes
17
<img src="logo.gif" alt="logo" />
Attribute alt with value "logo"
ยฉ Sun Technologies Inc.
Headings and Paragraphs
โ€ข Heading Tags (h1 โ€“ h6)
โ€ข Paragraph Tags
โ€ข Sections: div and span
18
<p>This is my first paragraph</p>
<p>This is my second paragraph</p>
<h1>Heading 1</h1>
<h2>Sub heading 2</h2>
<h3>Sub heading 3</h3>
<div style="background: skyblue;">
This is a div</div>
ยฉ Sun Technologies Inc.
Headings and Paragraphs โ€“ Example
19
<!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>
headings.html
ยฉ Sun Technologies Inc.
<!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>
Headings and Paragraphs โ€“ Example (2)
20
headings.html
ยฉ Sun Technologies Inc.
Introduction to HTML
HTML Document Structure in Depth
Preface
โ€ข It is important to have the correct vision and attitude towards
HTML
โ€ข HTML is only about structure, not appearance
โ€ข Browsers tolerate invalid HTML code and parse errors โ€“ you should
not.
22ยฉ Sun Technologies Inc.
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:
โ€ขSee http://w3.org/QA/2002/04/valid-dtd-list.html for a list
of possible doctypes
23
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
ยฉ Sun Technologies Inc.
The <head> Section
โ€ข Contains information that doesnโ€™t show directly on the viewable page
โ€ข Starts after the <!doctype> declaration
โ€ข Begins with <head> and ends with </head>
โ€ข Contains mandatory single <title> tag
โ€ข Can contain some other tags, e.g.
โ€ข<meta>
โ€ข<script>
โ€ข<style>
โ€ข<!โ€“- comments -->
24ยฉ Sun Technologies Inc.
<head> Section: <title> tag
โ€ขTitle should be placed between <head> and
</head> tags
โ€ขUsed to specify a title in the window title bar
โ€ขSearch engines and people rely on titles
25
<title>Telerik Academy โ€“ Winter Season 2009/2010
</title>
ยฉ Sun Technologies Inc.
<head> Section: <meta>
โ€ข Meta tags additionally describe the content contained within the
page
26
<meta name="description" content="HTML tutorial"
/>
<meta name="keywords" content="html, web design,
styles" />
<meta name="author" content="Chris Brewer" />
<meta http-equiv="refresh" content="5;
url=http://www.telerik.com" />
ยฉ Sun Technologies Inc.
<head> Section: <script>
โ€ข The <script> element is used to embed scripts into an HTML
document
โ€ข Script are executed in the client's Web browser
โ€ข Scripts can live in the <head> and in the <body> sections
โ€ข Supported client-side scripting languages:
โ€ข JavaScript (it is not Java!)
โ€ข VBScript
โ€ข JScript
27ยฉ Sun Technologies Inc.
The <script> Tag โ€“ Example
28
<!DOCTYPE HTML>
<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>
scripts-example.html
ยฉ Sun Technologies Inc.
<head> Section: <style>
โ€ขThe <style> element embeds formatting
information (CSS styles) into an HTML page
29
<html>
<head>
<style type="text/css">
p { font-size: 12pt; line-height: 12pt; }
p:first-letter { font-size: 200%; }
span { text-transform: uppercase; }
</style>
</head>
<body>
<p>Styles demo.<br />
<span>Test uppercase</span>.
</p>
</body>
</html>
style-example.html
ยฉ Sun Technologies Inc.
Comments: <!-- --> Tag
โ€ข Comments can exist anywhere between the <html></html> tags
โ€ข Comments start with <!-- and end with -->
30
<!โ€“- Telerik Logo (a JPG file) -->
<img src="logo.jpg" alt=โ€œTelerik Logo">
<!โ€“- Hyperlink to the web site -->
<a href="http://telerik.com/">Telerik</a>
<!โ€“- Show the news table -->
<table class="newstable">
...
ยฉ Sun Technologies Inc.
<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 </body>
31
<html>
<head><title>Test page</title></head>
<body>
<!-- This is the Web page body -->
</body>
</html>
ยฉ Sun Technologies Inc.
Text Formatting
โ€ข Text formatting tags modify the text between the opening tag and the
closing tag
โ€ข Ex. <b>Hello</b> makes โ€œHelloโ€ bold
<b></b> bold
<i></i> italicized
<u></u> underlined
<sup></sup> Samplesuperscript
<sub></sub> Samplesubscript
<strong></strong> strong
<em></em> emphasized
<pre></pre> Preformatted text
<blockquote></blockquote> Quoted text block
<del></del> Deleted text โ€“ strike through
32
ยฉ Sun Technologies Inc.
Text Formatting โ€“ Example
33
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Notice</h1>
<p>This is a <em>sample</em> Web page.</p>
<p><pre>Next paragraph:
preformatted.</pre></p>
<h2>More Info</h2>
<p>Specifically, weโ€™re using XHMTL 1.0 transitional.<br />
Next line.</p>
</body>
</html>
text-formatting.html
ยฉ Sun Technologies Inc.
Text Formatting โ€“ Example (2)
34
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Notice</h1>
<p>This is a <em>sample</em> Web page.</p>
<p><pre>Next paragraph:
preformatted.</pre></p>
<h2>More Info</h2>
<p>Specifically, weโ€™re using XHMTL 1.0 transitional.<br />
Next line.</p>
</body>
</html>
text-formatting.html
ยฉ Sun Technologies Inc.
Hyperlinks: <a> Tag
โ€ข Link to a document called form.html on the same server in the same
directory:
โ€ข Link to a document called parent.html on the same server in the parent
directory:
โ€ข Link to a document called cat.html on the same server in the
subdirectory stuff:
35
<a href="form.html">Fill Our Form</a>
<a href="../parent.html">Parent</a>
<a href="stuff/cat.html">Catalog</a>
ยฉ Sun Technologies Inc.
Hyperlinks: <a> Tag (2)
โ€ข Link to an external Web site:
โ€ข Always use a full URL, including "http://", not just "www.somesite.com"
โ€ข Using the target="_blank" attribute opens the link in a new window
โ€ข Link to an e-mail address:
36
<a href="http://www.devbg.org" target="_blank">BASD</a>
<a
href="mailto:bugs@example.com?subject=Bug+Report">
Please report bugs here (by e-mail only)</a>
ยฉ Sun Technologies Inc.
Hyperlinks: <a> Tag (3)
โ€ข Link to a document called apply-now.html
โ€ขOn the same server, in same directory
โ€ขUsing an image as a link button:
โ€ข Link to a document called index.html
โ€ขOn the same server, in the subdirectory english
of the parent directory:
37
<a href="apply-now.html"><img
src="apply-now-button.jpg" /></a>
<a href="../english/index.html">Switch to English
version</a>
ยฉ Sun Technologies Inc.
Hyperlinks and Sections
โ€ขLink to another location in the same
document:
โ€ขLink to a specific location in another
document:
38
<a href="#section1">Go to Introduction</a>
...
<h2 id="section1">Introduction</h2>
<a href="chapter3.html#section3.1.1">Go to Section 3.1.1</a>
<!โ€“- In chapter3.html -->
...
<div id="section3.1.1">
<h3>3.1.1. Technical Background</h3>
</div>
ยฉ Sun Technologies Inc.
Hyperlinks โ€“ Example
39
<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-now-button.jpgโ€
/></a> <br />
<a href="../english/index.html">Switch to English version</a> <br
/>
hyperlinks.html
ยฉ Sun Technologies Inc.
<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-now-button.jpgโ€ /></a>
<br />
<a href="../english/index.html">Switch to English version</a> <br />
hyperlinks.html
Hyperlinks โ€“ Example (2)
40ยฉ Sun Technologies Inc.
Links to the Same Document โ€“
Example
41
<h1>Table of Contents</h1>
<p><a href="#section1">Introduction</a><br />
<a href="#section2">Some background</A><br />
<a href="#section2.1">Project History</a><br />
...the rest of the table of contents...
<!-- The document text follows here -->
<h2 id="section1">Introduction</h2>
... Section 1 follows here ...
<h2 id="section2">Some background</h2>
... Section 2 follows here ...
<h3 id="section2.1">Project History</h3>
... Section 2.1 follows here ...
links-to-same-document.html
ยฉ Sun Technologies Inc.
Links to the Same Document โ€“
Example (2)
42
<h1>Table of Contents</h1>
<p><a href="#section1">Introduction</a><br />
<a href="#section2">Some background</A><br />
<a href="#section2.1">Project History</a><br />
...the rest of the table of contents...
<!-- The document text follows here -->
<h2 id="section1">Introduction</h2>
... Section 1 follows here ...
<h2 id="section2">Some background</h2>
... Section 2 follows here ...
<h3 id="section2.1">Project History</h3>
... Section 2.1 follows here ...
links-to-same-document.html
ยฉ Sun Technologies Inc.
๏‚ฎ Inserting an image with <img> tag:
๏‚ฎ Image attributes:
๏‚ฎ Example:
Images: <img> tag
src Location of image file (relative or absolute)
alt Substitute text for display (e.g. in text mode)
height Number of pixels of the height
width Number of pixels of the width
border Size of border, 0 for no border
<img src="/img/basd-logo.png">
<img src="./php.png" alt="PHP Logo" />
ยฉ Sun Technologies Inc. 43
Miscellaneous Tags
โ€ข <hr />: Draws a horizontal rule (line):
โ€ข <center></center>: Deprecated!
โ€ข <font></font>:
44
<hr size="5" width="70%" />
<center>Hello World!</center>
<font size="3" color="blue">Font3</font>
<font size="+4" color="blue">Font+4</font>
ยฉ Sun Technologies Inc.
Miscellaneous Tags โ€“ Example
45
<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>
misc.html
ยฉ Sun Technologies Inc.
a. Apple
b. Orange
c. Grapefruit
Ordered Lists: <ol> Tag
โ€ขCreate an Ordered List using <ol></ol>:
โ€ขAttribute values for type are 1, A, a, I, or i
46
1. Apple
2. Orange
3. Grapefruit
A. Apple
B. Orange
C. Grapefruit
I. Apple
II. Orange
III. Grapefruit
i. Apple
ii. Orange
iii. Grapefruit
<ol type="1">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ol>
ยฉ Sun Technologies Inc.
Unordered Lists: <ul> Tag
โ€ข Create an Unordered List using <ul></ul>:
โ€ข Attribute values for type are:
โ€ขdisc, circle or square
47
โ€ข Apple
โ€ข Orange
โ€ข Pear
o Apple
o Orange
o Pear
๏‚ง Apple
๏‚ง Orange
๏‚ง Pear
<ul type="disk">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ul>
ยฉ Sun Technologies Inc.
Definition lists: <dl> tag
โ€ข Create definition lists using <dl>
โ€ข Pairs of text and associated definition; text is in <dt> tag,
definition in <dd> tag
โ€ข Renders without bullets
โ€ข Definition is indented
48
<dl>
<dt>HTML</dt>
<dd>A markup language โ€ฆ</dd>
<dt>CSS</dt>
<dd>Language used to โ€ฆ</dd>
</dl>
ยฉ Sun Technologies Inc.
Lists โ€“ Example
49
<ol type="1">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ol>
<ul type="disc">
<li>Apple</li>
<li>Orange</li>
<li>Grapefruit</li>
</ul>
<dl>
<dt>HTML</dt>
<dd>A markup langโ€ฆ</dd>
</dl>
lists.html
ยฉ Sun Technologies Inc.
HTML Special Characters
ยฃ&pound;British Pound
โ‚ฌ&#8364;Euro
"&quot;Quotation Mark
ยฅ&yen;Japanese Yen
โ€”&mdash;Em Dash
&nbsp;Non-breaking Space
&&amp;Ampersand
>&gt;Greater Than
<&lt;Less Than
โ„ข&trade;Trademark Sign
ยฎ&reg;Registered Trademark Sign
ยฉ&copy;Copyright Sign
SymbolHTML EntitySymbol Name
50
ยฉ Sun Technologies Inc
Special Characters โ€“ Example
51
<p>[&gt;&gt;&nbsp;&nbsp;Welcome
&nbsp;&nbsp;&lt;&lt;]</p>
<p>&#9658;I have following cards:
A&#9827;, K&#9830; and 9&#9829;.</p>
<p>&#9658;I prefer hard rock &#9835;
music &#9835;</p>
<p>&copy; 2006 by Svetlin Nakov &amp; his team</p>
<p>Telerik Academyโ„ข</p>
special-chars.html
ยฉ Sun Technologies Inc.
Special Chars โ€“ Example (2)
52
<p>[&gt;&gt;&nbsp;&nbsp;Welcome
&nbsp;&nbsp;&lt;&lt;]</p>
<p>&#9658;I have following cards:
A&#9827;, K&#9830; and 9&#9829;.</p>
<p>&#9658;I prefer hard rock &#9835;
music &#9835;</p>
<p>&copy; 2006 by Svetlin Nakov &amp; his team</p>
<p>Telerik Academyโ„ข</p>
special-chars.html
ยฉ Sun Technologies Inc.
Using <DIV> and <SPAN>
Block and Inline Elements
Block and Inline Elements
โ€ข Block elements add a line break before and after them
โ€ข <div> is a block element
โ€ข Other block elements are <table>, <hr>, headings, lists, <p> and etc.
โ€ข Inline elements donโ€™t break the text before and after them
โ€ข <span> is an inline element
โ€ข Most HTML elements are inline, e.g. <a>
54
ยฉ Sun Technologies Inc.
The <div> Tag
โ€ข <div> creates logical divisions within a page
โ€ข Block style element
โ€ข Used with CSS
โ€ข Example:
55
<div style="font-size:24px; color:red">DIV example</div>
<p>This one is <span style="color:red; font-
weight:bold">only a test</span>.</p>
div-and-span.html
ยฉ Sun Technologies Inc.
The <span> Tag
โ€ข Inline style element
โ€ข Useful for modifying a specific portion of text
โ€ข Don't create a separate area (paragraph) in the
document
โ€ข Very useful with CSS
56
<p>This one is <span style="color:red; font-
weight:bold">only a test</span>.</p>
<p>This one is another <span style="font-size:32px; font-
weight:bold">TEST</span>.</p>
span.html
ยฉ Sun Technologies Inc.
HTML Tables
HTML Tables
โ€ข Tables represent tabular data
โ€ข A table consists of one or several rows
โ€ข Each row has one or more columns
โ€ข Tables comprised of several core tags: <table></table>: begin /
end the table
<tr></tr>: create a table row
<td></td>: create tabular data (cell)
โ€ข Tables should not be used for layout. Use CSS floats
58ยฉ Sun Technologies Inc.
HTML Tables (2)
โ€ข Start and end of a table
โ€ข Start and end of a row
โ€ข Start and end of a cell in a row
59
<table> ... </table>
<tr> ... </tr>
<td> ... </td>
ยฉ Sun Technologies Inc.
Simple HTML Tables โ€“ Example
60
<table cellspacing="0" cellpadding="5">
<tr>
<td><img src="ppt.gif"></td>
<td><a href="lecture1.ppt">Lecture 1</a></td>
</tr>
<tr>
<td><img src="ppt.gif"></td>
<td><a href="lecture2.ppt">Lecture 2</a></td>
</tr>
<tr>
<td><img src="zip.gif"></td>
<td><a href="lecture2-demos.zip">
Lecture 2 - Demos</a></td>
</tr>
</table>
ยฉ Sun Technologies Inc.
<table cellspacing="0" cellpadding="5">
<tr>
<td><img src="ppt.gif"></td>
<td><a href="lecture1.ppt">Lecture 1</a></td>
</tr>
<tr>
<td><img src="ppt.gif"></td>
<td><a href="lecture2.ppt">Lecture 2</a></td>
</tr>
<tr>
<td><img src="zip.gif"></td>
<td><a href="lecture2-demos.zip">
Lecture 2 - Demos</a></td>
</tr>
</table>
Simple HTML Tables โ€“ Example (2)
61ยฉ Sun Technologies Inc.
Complete HTML Tables
โ€ข Table rows split into three semantic sections: header, body and
footer
โ€ข <thead> denotes table header and contains <th> elements, instead of
<td> elements
โ€ข <tbody> denotes collection of table rows that contain the very data
โ€ข <tfoot> denotes table footer but comes BEFORE the <tbody> tag
โ€ข <colgroup> and <col> define columns (most often used to set column
widths)
62ยฉ Sun Technologies Inc.
Complete HTML Table: Example
63
<table>
<colgroup>
<col style="width:100px" /><col />
</colgroup>
<thead>
<tr><th>Column 1</th><th>Column 2</th></tr>
</thead>
<tfoot>
<tr><td>Footer 1</td><td>Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>Cell 1.1</td><td>Cell 1.2</td></tr>
<tr><td>Cell 2.1</td><td>Cell 2.2</td></tr>
</tbody>
</table>
header
footer
Last comes the body
(data)
th
columns
ยฉ Sun Technologies Inc.
<table>
<colgroup>
<col style="width:200px" /><col />
</colgroup>
<thead>
<tr><th>Column 1</th><th>Column 2</th></tr>
</thead>
<tfoot>
<tr><td>Footer 1</td><td>Footer 2</td></tr>
</tfoot>
<tbody>
<tr><td>Cell 1.1</td><td>Cell 1.2</td></tr>
<tr><td>Cell 2.1</td><td>Cell 2.2</td></tr>
</tbody>
</table>
Complete HTML Table:
Example (2)
64
table-full.html
Although the footer
is before the data in
the code, it is
displayed last
By default, header
text is bold and
centered.
ยฉ Sun Technologies Inc.
Nested Tables
โ€ขTable data โ€œcellsโ€ (<td>) can contain nested
tables (tables within tables):
65
<table>
<tr>
<td>Contact:</td>
<td>
<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
</tr>
</table>
</td>
</tr>
</table>
nested-tables.html
ยฉ Sun Technologies Inc.
๏‚ฎ cellpadding
๏‚ฎ Defines the empty
space around the
cell content
๏‚ฎ cellspacing
๏‚ฎ Defines the
empty space
between cells
Cell Spacing and Padding
โ€ข Tables have two important attributes:
66
cell cell
cell cell
cell
cell
cell
cell
ยฉ Sun Technologies Inc.
Cell Spacing and Padding โ€“
Example
67
<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>
table-cells.html
ยฉ Sun Technologies Inc.
Cell Spacing and Padding โ€“
Example (2)
68
<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>
table-
cells.html
ยฉ Sun Technologies Inc.
๏‚ฎ rowspan
๏‚ฎ Defines how
many rows the
cell occupies
๏‚ฎ colspan
๏‚ฎ Defines how
many columns
the cell occupies
Column and Row Span
โ€ข Table cells have two important attributes:
69
cell[1,1
]
cell[1,2]
cell[2,1]
colspan="
1"
colspan="
1"
colspan="
2"
cell[1,1]
cell[1,2
]
cell[2,1
]
rowspan="
2"
rowspan="
1"
rowspan="
1"
ยฉ Sun Technologies Inc.
Column and Row Span โ€“ Example
70
<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>
table-colspan-rowspan.html
ยฉ Sun Technologies Inc.
<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>
Column and Row Span โ€“
Example (2)
71
table-colspan-rowspan.html
Cell[2,3]Cell[1,3]
Cell[3,2]
Cell[2,2]
Cell[1,2]
Cell[2,1]Cell[1,1]
ยฉ Sun Technologies Inc.
HTML FormsEntering User Data from a Web
Page
HTML Forms
โ€ข Forms are the primary method for gathering data from site visitors
โ€ข Create a form block with
โ€ข Example:
73
<form></form>
<form name="myForm" method="post"
action="path/to/some-script.php">
...
</form>
The "action" attribute tells where
the form data should be sent
The โ€œmethod" attribute tells
how the form data should be
sent โ€“ via GET or POST request
ยฉ Sun Technologies Inc.
Form Fields
โ€ขSingle-line text input fields:
โ€ขMulti-line textarea fields:
โ€ขHidden fields contain data not shown to the
user:
โ€ขOften used by JavaScript code
76
<input type="text" name="FirstName"
value="This is a text field" />
<textarea name="Comments">This is a multi-line
text field</textarea>
<input type="hidden" name="Account"
value="This is a hidden text field" />
ยฉ Sun Technologies Inc.
Fieldsets
โ€ขFieldsets are used to enclose a group of
related form fields:
75
<form method="post" action="form.aspx">
<fieldset>
<legend>Client Details</legend>
<input type="text" id="Name" />
<input type="text" id="Phone" />
</fieldset>
<fieldset>
<legend>Order Details</legend>
<input type="text" id="Quantity" />
<textarea cols="40" rows="10"
id="Remarks"></textarea>
</fieldset>
</form>
ยฉ Sun Technologies Inc.
Form Input Controls
โ€ขCheckboxes:
โ€ขRadio buttons:
โ€ขRadio buttons can be grouped, allowing only
one to be selected from a group:
76
<input type="checkbox" name="fruit" value="apple" />
<input type="radio" name="title" value="Mr." />
<input type="radio" name="city" value="Lom" />
<input type="radio" name="city" value="Ruse" />
ยฉ Sun Technologies Inc.
Other Form Controls
โ€ข Dropdown menus:
โ€ข Submit button:
77
<select name="gender">
<option value="Value 1"
selected="selected">Male</option>
<option value="Value
2">Female</option>
<option value="Value 3">Other</option>
</select>
<input type="submit" name="submitBtn" value="Apply
Now" />
ยฉ Sun Technologies Inc.
Other Form Controls (2)
Reset button โ€“ brings the form to its initial state
Image button โ€“ acts like submit but image is
displayed and click coordinates are sent
Ordinary button โ€“ used for Javascript, no default
action
78
<input type="reset" name="resetBtn" value="Reset the
form" />
<input type="image" src="submit.gif"
name="submitBtn" alt="Submit" />
<input type="button" value="click me" />
ยฉ Sun Technologies Inc.
Other Form Controls (3)
โ€ขPassword input โ€“ a text field which masks
the entered text with * signs
โ€ขMultiple select field โ€“ displays the list of
items in multiple lines, instead of one
79
<input type="password" name="pass" />
<select name="products" multiple="multiple">
<option value="Value 1"
selected="selected">keyboard</option>
<option value="Value 2">mouse</option>
<option value="Value 3">speakers</option>
</select>
ยฉ Sun Technologies Inc.
Other Form Controls (4)
โ€ขFile input โ€“ a field used for uploading files
โ€ขWhen used, it requires the form element to
have a specific attribute:
80
<input type="file" name="photo" />
<form enctype="multipart/form-data">
...
<input type="file" name="photo" />
...
</form>
ยฉ Sun Technologies Inc.
Labels
โ€ขForm labels are used to associate an
explanatory text to a form field using the
field's ID.
โ€ขClicking on a label focuses its associated
field (checkboxes are toggled, radio buttons
are checked)
โ€ขLabels are both a usability and accessibility
feature and are required in order to pass
accessibility validation.
81
<label for="fn">First Name</label>
<input type="text" id="fn" />
ยฉ Sun Technologies Inc.
HTML Forms โ€“ Example
82
<form method="post" action="apply-now.php">
<input name="subject" type="hidden" value="Class" />
<fieldset><legend>Academic information</legend>
<label for="degree">Degree</label>
<select name="degree" id="degree">
<option value="BA">Bachelor of Art</option>
<option value="BS">Bachelor of Science</option>
<option value="MBA" selected="selected">Master of
Business Administration</option>
</select>
<br />
<label for="studentid">Student ID</label>
<input type="password" name="studentid" />
</fieldset>
<fieldset><legend>Personal Details</legend>
<label for="fname">First Name</label>
<input type="text" name="fname" id="fname" />
<br />
<label for="lname">Last Name</label>
<input type="text" name="lname" id="lname" />
form.html
ยฉ Sun Technologies Inc.
HTML Forms โ€“ Example (2)
83
<br />
Gender:
<input name="gender" type="radio" id="gm" value="m" />
<label for="gm">Male</label>
<input name="gender" type="radio" id="gf" value="f" />
<label for="gf">Female</label>
<br />
<label for="email">Email</label>
<input type="text" name="email" id="email" />
</fieldset>
<p>
<textarea name="terms" cols="30" rows="4"
readonly="readonly">TERMS AND CONDITIONS...</textarea>
</p>
<p>
<input type="submit" name="submit" value="Send Form" />
<input type="reset" value="Clear Form" />
</p>
</form>
form.html (continued)
ยฉ Sun Technologies Inc.
form.html (continued)
HTML Forms โ€“
Example (3)
84ยฉ Sun Technologies Inc.
TabIndex
โ€ข The TabIndex HTML attribute controls the order in which form
fields and hyperlinks are focused when repeatedly pressing the
TAB key
โ€ข TabIndex="0" (zero) - "natural" order
โ€ข If X > Y, then elements with TabIndex="X" are iterated before elements
with TabIndex="Y"
โ€ข Elements with negative TabIndex are skipped, however, this is not
defined in the standard
85
<input type="text" tabindex="10" />
ยฉ Sun Technologies Inc.
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
engines, etc.)
โ€ข A <noframes> element is used to provide content for non-compatible
agents.
87ยฉ Sun Technologies Inc.
HTML Frames โ€“ Demo
88
<html>
<head><title>Frames Example</title></head>
<frameset cols="180px,*,150px">
<frame src="left.html" />
<frame src="middle.html" />
<frame src="right.html" />
</frameset>
</html>
frames.html
๏‚ฎ Note the target attribute applied to the <a>
elements in the left frame.
ยฉ Sun Technologies Inc.
Inline Frames: <iframe>
โ€ข Inline frames provide a way to show one website inside another
website:
89
<iframe name="iframeGoogle" width="600" height="400"
src="http://www.google.com" frameborder="yes"
scrolling="yes"></iframe>
iframe-demo.html
ยฉ Sun Technologies Inc.
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
โ€ข Visibility, Display, Overflow
โ€ข CSS Development Tools
91ยฉ Sun Technologies Inc.
CSS: A New Philosophy
โ€ข Separate content from presentation!
92
Title
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.
Suspendisse at pede ut purus
malesuada dictum. Donec
vitae neque non magna
aliquam dictum.
โ€ข Vestibulum et odio et ipsum
โ€ข accumsan accumsan. Morbi
at
โ€ข arcu vel elit ultricies porta.
Proin
tortor purus, luctus non,
aliquam nec, interdum vel, mi.
Sed nec quam nec odio lacinia
molestie. Praesent augue
tortor, convallis eget, euismod
nonummy, lacinia ut, risus.
Bold
Italics
Indent
Content
(HTML document)
Presentation
(CSS Document)
ยฉ Sun Technologies Inc.
The Resulting Page
93
Title
Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Suspendisse at pede ut
purus malesuada dictum. Donec vitae
neque non magna aliquam dictum.
โ€ข Vestibulum et odio et ipsum
โ€ข accumsan accumsan. Morbi at
โ€ข arcu vel elit ultricies porta. Proin
Tortor purus, luctus non, aliquam nec,
interdum vel, mi. Sed nec quam nec odio
lacinia molestie. Praesent augue tortor,
convallis eget, euismod nonummy, lacinia
ut, risus.
ยฉ Sun Technologies Inc.
CSS Intro
Styling with Cascading
Stylesheets
CSS Introduction
โ€ขCascading Style Sheets (CSS)
โ€ขUsed to describe the presentation of
documents
โ€ขDefine sizes, spacing, fonts, colors, layout, etc.
โ€ขImprove content accessibility
โ€ขImprove flexibility
โ€ขDesigned to separate presentation from
content
โ€ขDue to CSS, all HTML presentation tags and
attributes are deprecated, e.g. font, center,
etc.
95ยฉ Sun Technologies Inc.
CSS Introduction (2)
โ€ข CSS can be applied to any XML document
โ€ข Not just to HTML / XHTML
โ€ข CSS can specify different styles for different media
โ€ข On-screen
โ€ข In print
โ€ข Handheld, projection, etc.
โ€ข โ€ฆ even by voice or Braille-based reader
96ยฉ Sun Technologies Inc.
Why โ€œCascadingโ€?
โ€ข Priority scheme determining which style rules apply to element
โ€ข Cascade priorities or specificity (weight) are calculated and assigned to
the rules
โ€ข Child elements in the HTML DOM tree inherit styles from their parent
โ€ข Can override them
โ€ข Control via !important rule
97
ยฉ Sun Technologies Inc.
Why โ€œCascadingโ€? (2)
98ยฉ Sun Technologies Inc.
Why โ€œCascadingโ€? (3)
โ€ข Some CSS styles are inherited and some not
โ€ข Text-related and list-related properties are inherited - color, font-
size, font-family, line-height, text-align, list-
style, etc
โ€ข Box-related and positioning styles are not inherited - width,
height, border, margin, padding, position, float,
etc
โ€ข<a> elements do not inherit color and text-decoration
99ยฉ Sun Technologies Inc.
Style Sheets Syntax
โ€ขStylesheets consist of rules, selectors,
declarations, properties and values
โ€ขSelectors are separated by commas
โ€ขDeclarations are separated by semicolons
โ€ขProperties and values are separated by
colons
100
h1,h2,h3 { color: green; font-weight: bold; }
http://css.maxdesign.com.a
u/
ยฉ Sun Technologies Inc.
Selectors
โ€ข Selectors determine which element the rule applies to:
โ€ข All elements of specific type (tag)
โ€ข Those that mach a specific attribute (id, class)
โ€ข Elements may be matched depending on how they are nested in the
document tree (HTML)
โ€ข Examples:
101
.header a { color: green }
#menu>li { padding-top: 8px }
ยฉ Sun Technologies Inc.
Selectors (2)
โ€ขThree primary kinds of selectors:
โ€ข By tag (type selector):
โ€ข By element id:
โ€ข By element class name (only for HTML):
โ€ขSelectors can be combined with commas:
This will match <h1> tags, elements with class
link, and element with id top-link
102
h1 { font-family: verdana,sans-serif; }
#element_id { color: #ff0000; }
.myClass {border: 1px solid red}
h1, .link, #top-link {font-weight: bold}
ยฉ Sun Technologies Inc.
Selectors (3)
โ€ข Pseudo-classes define state
โ€ข :hover, :visited, :active , :lang
โ€ข Pseudo-elements define element "parts" or are used to
generate content
โ€ข :first-line , :before, :after
103
a:hover { color: red; }
p:first-line { text-transform: uppercase; }
.title:before { content: "ยป"; }
.title:after { content: "ยซ"; }
ยฉ Sun Technologies Inc.
Selectors (4)
โ€ขMatch relative to element placement:
This will match all <a> tags that are inside of <p>
โ€ข* โ€“ universal selector (avoid or use with care!):
This will match all descendants of <p> element
โ€ข+ selector โ€“ used to match โ€œnext siblingโ€:
This will match all siblings with class name link
that appear immediately after <img> tag
104
p a {text-decoration: underline}
p * {color: black}
img + .link {float:right}
ยฉ Sun Technologies Inc.
Selectors (5)
โ€ข> selector โ€“ matches direct child nodes:
This will match all elements with class error, direct
children of <p> tag
โ€ข[ ] โ€“ matches tag attributes by regular expression:
This will match all <img> tags with alt attribute
containing the word logo
โ€ข.class1.class2 (no space) - matches elements with
both (all) classes applied at the same time
105
p > .error {font-size: 8px}
img[alt~=logo] {border: none}
ยฉ Sun Technologies Inc.
Values in the CSS Rules
โ€ขColors are set in RGB format (decimal or hex):
โ€ขExample: #a0a6aa = rgb(160, 166, 170)
โ€ขPredefined color aliases exist: black, blue, etc.
โ€ขNumeric values are specified in:
โ€ขPixels, ems, e.g. 12px , 1.4em
โ€ขPoints, inches, centimeters, millimeters
โ€ข E.g. 10pt , 1in, 1cm, 1mm
โ€ขPercentages, e.g. 50%
โ€ข Percentage of what?...
โ€ข Zero can be used with no unit: border: 0;
106ยฉ Sun Technologies Inc.
Default Browser Styles
โ€ข Browsers have default CSS styles
โ€ข Used when there is no CSS information or any other style information
in the document
โ€ข Caution: default styles differ in browsers
โ€ข E.g. margins, paddings and font sizes differ most often and usually
developers reset them
107
* { margin: 0; padding: 0; }
body, h1, p, ul, li { margin: 0; padding: 0; }
ยฉ Sun Technologies Inc.
Linking HTML and CSS
โ€ข HTML (content) and CSS (presentation) can be linked in three ways:
โ€ข Inline: the CSS rules in the style attribute
โ€ข No selectors are needed
โ€ข Embedded: in the <head> in a <style> tag
โ€ข External: CSS rules in separate file (best)
โ€ข Usually a file with .css extension
โ€ข Linked via <link rel="stylesheet" href=โ€ฆ> tag or @import directive
in embedded CSS block
108ยฉ Sun Technologies Inc.
Linking HTML and CSS (2)
โ€ข Using external files is highly recommended
โ€ข Simplifies the HTML document
โ€ข Improves page load speed as the CSS file is cached
109ยฉ Sun Technologies Inc.
Inline Styles: Example
110
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inline Styles</title>
</head>
<body>
<p>Here is some text</p>
<!--Separate multiple styles with a semicolon-->
<p style="font-size: 20pt">Here is some
more text</p>
<p style="font-size: 20pt;color:
#0000FF" >Even more text</p>
</body>
</html>
inline-styles.html
ยฉ Sun Technologies Inc.
Inline Styles: Example
111
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inline Styles</title>
</head>
<body>
<p>Here is some text</p>
<!--Separate multiple styles with a semicolon-->
<p style="font-size: 20pt">Here is some
more text</p>
<p style="font-size: 20pt;color:
#0000FF" >Even more text</p>
</body>
</html>
inline-styles.html
ยฉ Sun Technologies Inc.
CSS Cascade (Precedence)
โ€ข There are browser, user and author stylesheets with "normal" and
"important" declarations
โ€ข Browser styles (least priority)
โ€ข Normal user styles
โ€ข Normal author styles (external, in head, inline)
โ€ข Important author styles
โ€ข Important user styles (max priority)
112
a { color: red !important ; }
http://www.slideshare.net/maxdesign/css-cascade-
1658158
ยฉ Sun Technologies Inc.
CSS Specificity
โ€ข CSS specificity is used to determine the precedence of CSS
style declarations with the same origin. Selectors are what
matters
โ€ข Simple calculation: #id = 100, .class = 10, :pseudo = 10, [attr] = 10, tag
= 1, * = 0
โ€ข Same number of points? Order matters.
โ€ข See also:
โ€ข http://www.smashingmagazine.com/2007/07/27/css-specificity-
things-you-should-know/
โ€ข http://css.maxdesign.com.au/selectutorial/advanced_conflict.ht
m
113ยฉ Sun Technologies Inc.
Embedded Styles
โ€ข Embedded in the HTML in the <style> tag:
โ€ข The <style> tag is placed in the <head> section of the document
โ€ข type attribute specifies the MIME type
โ€ข MIME describes the format of the content
โ€ข Other MIME types include text/html, image/gif, text/javascript โ€ฆ
โ€ข Used for document-specific styles
114
<style type="text/css">
ยฉ Sun Technologies Inc.
Embedded Styles: Example
115
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.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>
embedded-stylesheets.html
ยฉ Sun Technologies Inc.
Embedded Styles: Example (2)
116
โ€ฆ
<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>
ยฉ Sun Technologies Inc.
โ€ฆ
<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>
Embedded Styles: Example (3)
117ยฉ Sun Technologies Inc.
External CSS Styles
โ€ข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/)
โ€ขlink tag (with a rel attribute)
โ€ขSpecifies a relationship between current document
and another document
โ€ข link elements should be in the <head>
118
<link rel="stylesheet" type="text/css"
href="styles.css">
ยฉ Sun Technologies Inc.
External CSS Styles (2)
@import
โ€ข Another way to link external CSS files
โ€ข Example:
โ€ข Ancient browsers do not recognize @import
โ€ข Use @import in an external CSS file to workaround the IE 32 CSS file limit
119
<style type="text/css">
@import url("styles.css");
/* same as */
@import "styles.css";
</style>
ยฉ Sun Technologies Inc.
External Styles: Example
120
/* CSS Document */
a { text-decoration: none }
a:hover { text-decoration: underline;
color: red;
background-color: #CCFFCC }
li em { color: red;
font-weight: bold }
ul { margin-left: 2cm }
ul ul { text-decoration: underline;
margin-left: .5cm }
styles.css
ยฉ Sun Technologies Inc.
External Styles: Example (2)
121
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Importing style sheets</title>
<link type="text/css" rel="stylesheet"
href="styles.css" />
</head>
<body>
<h1>Shopping list for <em>Monday</em>:</h1>
<li>Milk</li>
โ€ฆ
external-styles.html
ยฉ Sun Technologies Inc.
External Styles: Example (3)
122
โ€ฆ
<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>
ยฉ Sun Technologies Inc.
โ€ฆ
<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>
External Styles: Example (4)
123ยฉ Sun Technologies Inc.
Text-related CSS Properties
โ€ขcolor โ€“ specifies the color of the text
โ€ขfont-size โ€“ size of font: xx-small, x-small, small,
medium, large, x-large, xx-large, smaller, larger
or numeric value
โ€ขfont-family โ€“ comma separated font names
โ€ขExample: verdana, sans-serif, etc.
โ€ขThe browser loads the first one that is available
โ€ขThere should always be at least one generic font
โ€ขfont-weight can be normal, bold, bolder, lighter
or a number in range [100 โ€ฆ 900]
124
ยฉ Sun Technologies Inc.
CSS Rules for Fonts (2)
โ€ข font-style โ€“ styles the font
โ€ข Values: normal, italic, oblique
โ€ข text-decoration โ€“ decorates the text
โ€ข Values: none, underline, line-trough, overline, blink
โ€ข text-align โ€“ defines the alignment of text or other content
โ€ข Values: left, right, center, justify
125ยฉ Sun Technologies Inc.
Shorthand Font Property
โ€ข font
โ€ข Shorthand rule for setting multiple font properties at the same time
is equal to writing this:
126
font:italic normal bold 12px/16px verdana
font-style: italic;
font-variant: normal;
font-weight: bold;
font-size: 12px;
line-height: 16px;
font-family: verdana;
ยฉ Sun Technologies Inc.
Backgrounds
โ€ข background-image
โ€ข URL of image to be used as background, e.g.:
โ€ข background-color
โ€ข Using color and image and the same time
โ€ข background-repeat
โ€ข repeat-x, repeat-y, repeat, no-repeat
โ€ข background-attachment
โ€ข fixed / scroll
127
background-image:url("back.gif");
ยฉ Sun Technologies Inc.
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:
128
background-position: top left;
background-position: -5px 50%;
ยฉ Sun Technologies Inc.
Background Shorthand Property
โ€ขbackground: shorthand rule for setting
background properties at the same time:
is equal to writing:
โ€ขSome browsers will not apply BOTH color and
image for background if using shorthand rule
129
background: #FFF0C0 url("back.gif") no-repeat fixed
top;
background-color: #FFF0C0;
background-image: url("back.gif");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: top;
ยฉ Sun Technologies Inc.
Background-image or <img>?
โ€ข Background images allow you to save many image tags from
the HTML
โ€ข Leads to less code
โ€ข More content-oriented approach
โ€ข All images that are not part of the page content (and are used
only for "beautification") should be moved to the CSS
130ยฉ Sun Technologies Inc.
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-color, โ€ฆ
131ยฉ Sun Technologies Inc.
Border Shorthand Property
โ€ข border: shorthand rule for setting border properties at once:
is equal to writing:
โ€ข Specify different borders for the sides via shorthand rules:
border-top, border-left, border-right, border-bottom
โ€ข When to avoid border:0
132
border: 1px solid red
border-width:1px;
border-color:red;
border-style:solid;
ยฉ Sun Technologies Inc.
Width and Height
โ€ข width โ€“ defines numerical value for the width of element, e.g.
200px
โ€ข height โ€“ defines numerical value for the height of element, e.g.
100px
โ€ข By default the height of an element is defined by its content
โ€ข Inline elements do not apply height, unless you change their
display style.
133ยฉ Sun Technologies Inc.
Margin and Padding
โ€ข margin and padding define the spacing around the element
โ€ข Numerical value, e.g. 10px or -5px
โ€ข Can be defined for each of the four sides separately - margin-top,
padding-left, โ€ฆ
โ€ข margin is the spacing outside of the border
โ€ข padding is the spacing between the border and the content
โ€ข What are collapsing margins?
134ยฉ Sun Technologies Inc.
Margin and Padding: Short Rules
โ€ข margin: 5px;
โ€ข Sets all four sides to have margin of 5 px;
โ€ข margin: 10px 20px;
โ€ข top and bottom to 10px, left and right to 20px;
โ€ข margin: 5px 3px 8px;
โ€ข top 5px, left/right 3px, bottom 8px
โ€ข margin: 1px 3px 5px 7px;
โ€ข top, right, bottom, left (clockwise from top)
โ€ข Same for padding
135ยฉ Sun Technologies Inc.
The Box Model
136ยฉ Sun Technologies Inc.
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
137ยฉ Sun Technologies Inc.
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
138ยฉ Sun Technologies Inc.
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
โ€ข Their position and size is ignored when calculating the size of parent
element or position of surrounding elements
โ€ข Overlaid according to their z-index
โ€ข Inline fixed or absolutely positioned elements can apply height like
block-level elements
139ยฉ Sun Technologies Inc.
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
โ€ข Understanding stacking context
140
Each positioned element creates a stacking
context.
Elements in different stacking contexts are
overlapped according to the stacking order
of their containers. For example, there is no
way for #A1 and #A2 (children of #A) to be
placed over #B without increasing the z-
index of #A.
ยฉ Sun Technologies Inc.
Inline element positioning
โ€ข vertical-align: sets the vertical-alignment of an inline element,
according to the line height
โ€ข Values: baseline, sub, super, top, text-top, middle, bottom, text-bottom
or numeric
๏‚ฎ Also used for content of table cells (which apply middle alignment by
default)
141ยฉ Sun Technologies Inc.
Float
โ€ข float: the element โ€œfloatsโ€ to one side
โ€ข left: places the element on the left and following content on the right
โ€ข right: places the element on the right and following content on the left
โ€ข floated elements should come before the content that will wrap around
them in the code
โ€ข margins of floated elements do not collapse
โ€ข floated inline elements can apply height
142ยฉ Sun Technologies Inc.
Float (2)
โ€ข How floated elements are positioned
143ยฉ Sun Technologies Inc.
Clear
โ€ข clear
โ€ข Sets the sides of the element where other floating elements are NOT
allowed
โ€ข Used to "drop" elements below floated ones or expand a container,
which contains only floated children
โ€ข Possible values: left, right, both
โ€ขClearing floats
โ€ข additional element (<div>) with a clear style
144ยฉ Sun Technologies Inc.
Clear (2)
โ€ขClearing floats (continued)
โ€ข :after { content: ""; display: block; clear: both; height: 0; }
โ€ข Triggering hasLayout in IE expands a container of floated elements
โ€ข display: inline-block;
โ€ข zoom: 1;
145ยฉ Sun Technologies Inc.
Opacity
โ€ข opacity: specifies the opacity of the element
โ€ข Floating point number from 0 to 1
โ€ข For old Mozilla browsers use โ€“moz-opacity
โ€ข For IE use filter:alpha(opacity=value) where value is from 0 to 100;
also, "binary and script behaviors" must be enabled and hasLayout
must be triggered, e.g. with zoom:1
146ยฉ Sun Technologies Inc.
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
147ยฉ Sun Technologies Inc.
Display
โ€ข display: controls the display of the element and the way it is
rendered and if breaks should be placed before and after the
element
โ€ข inline: no breaks are placed before and after (<span> is an inline
element)
โ€ข block: breaks are placed before AND after the element (<div> is a
block element)
148ยฉ Sun Technologies Inc.
Display (2)
โ€ข display: controls the display of the element and the way it is
rendered and if breaks should be placed before and after the
element
โ€ข none: element is hidden and its dimensions are not used to calculate
the surrounding elements rendering (differs from visibility: hidden!)
โ€ข There are some more possible values, but not all browsers support
them
โ€ข Specific displays like table-cell and table-row
149ยฉ Sun Technologies Inc.
Overflow
โ€ขoverflow: defines the behavior of element when
content needs more space than you have specified
by the size properties or for other reasons. Values:
โ€ขvisible (default) โ€“ content spills out of the element
โ€ขauto - show scrollbars if needed
โ€ขscroll โ€“ always show scrollbars
โ€ขhidden โ€“ any content that cannot fit is clipped
150
ยฉ Sun Technologies Inc.
Other CSS Properties
โ€ข cursor: specifies the look of the mouse cursor when placed
over the element
โ€ข Values: crosshair, help, pointer, progress, move, hair, col-resize, row-
resize, text, wait, copy, drop, and others
โ€ข white-space โ€“ controls the line breaking of text. Value is one of:
โ€ข nowrap โ€“ keeps the text on one line
1. normal (default) โ€“ browser decides whether to brake the lines if
needed
โ€ข 15111ยฉ Sun Technologies Inc.
Benefits of using CSS
โ€ข More powerful formatting than using presentation tags
โ€ข Your pages load faster, because browsers cache the .css files
โ€ข Increased accessibility, because rules can be defined according
given media
โ€ข Pages are easier to maintain and update
152ยฉ Sun Technologies Inc.
Maintenance Example
153
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
Title
Some random
text here. You
canโ€™t read it
anyway! Har
har har! Use
Css.
CSS
file
ยฉ Sun Technologies Inc.
CSS Development Tools
โ€ข Visual Studio โ€“ CSS Editor
154ยฉ Sun Technologies Inc.
CSS Development Tools (3)
โ€ข Firebug โ€“ add-on to Firefox used to examine and adjust CSS
and HTML
155ยฉ Sun Technologies Inc.
CSS Development Tools (4)
โ€ข IE Developer Toolbar โ€“ add-on to IE used to examine CSS and
HTML (press [F12])
156ยฉ Sun Technologies Inc.
Introduction to JavaScript
Table of Contents
โ€ข What is DHTML?
โ€ข DHTML Technologies
โ€ข XHTML, CSS, JavaScript, DOM
158ยฉ Sun Technologies Inc.
Table of Contents (2)
โ€ข Introduction to JavaScript
โ€ข What is JavaScript
โ€ข Implementing JavaScript into Web pages
โ€ข In <head> part
โ€ข In <body> part
โ€ข In external .js file
159
ยฉ Sun Technologies Inc.
Table of Contents (3)
โ€ข JavaScript Syntax
โ€ข JavaScript operators
โ€ข JavaScript Data Types
โ€ข JavaScript Pop-up boxes
โ€ข alert, confirm and prompt
โ€ข Conditional and switch statements, loops and functions
โ€ข Document Object Model
โ€ข Debugging in JavaScript
160ยฉ Sun Technologies Inc.
DHTML
Dynamic Behavior at the Client Side
What is DHTML?
โ€ข Dynamic HTML (DHTML)
โ€ข Makes possible a Web page to react and change in response to the userโ€™s
actions
โ€ข DHTML = HTML + CSS + JavaScript
162
DHTML
XHTML CSS JavaScript DOM
ยฉ Sun Technologies Inc.
DTHML = HTML + CSS + JavaScript
โ€ข HTML defines Web sites content through semantic tags (headings,
paragraphs, lists, โ€ฆ)
โ€ข CSS defines 'rules' or 'styles' for presenting every aspect of an HTML
document
โ€ข Font (family, size, color, weight, etc.)
โ€ข Background (color, image, position, repeat)
โ€ข Position and layout (of any object on the page)
โ€ข JavaScript defines dynamic behavior
โ€ข Programming logic for interaction with the user, to handle events, etc.
163ยฉ Sun Technologies Inc.
JavaScript
Dynamic Behavior in a Web
Page
JavaScript
โ€ข JavaScript is a front-end scripting language developed by Netscape
for dynamic content
โ€ข Lightweight, but with limited capabilities
โ€ข Can be used as object-oriented language
โ€ข Client-side technology
โ€ข Embedded in your HTML page
โ€ข Interpreted by the Web browser
โ€ข Simple and flexible
โ€ข Powerful to manipulate the DOM
165ยฉ Sun Technologies Inc.
JavaScript Advantages
โ€ข JavaScript allows interactivity such as:
โ€ข Implementing form validation
โ€ข React to user actions, e.g. handle keys
โ€ข Changing an image on moving mouse over it
โ€ข Sections of a page appearing and disappearing
โ€ข Content loading and changing dynamically
โ€ข Performing complex calculations
โ€ข Custom HTML controls, e.g. scrollable table
โ€ข Implementing AJAX functionality
166ยฉ Sun Technologies Inc.
What Can JavaScript Do?
โ€ข Can handle events
โ€ข Can read and write HTML elements and modify the DOM tree
โ€ข Can validate form data
โ€ข Can access / modify browser cookies
โ€ข Can detect the userโ€™s browser and OS
โ€ข Can be used as object-oriented language
โ€ข Can handle exceptions
โ€ข Can perform asynchronous server calls (AJAX)
167
ยฉ Sun Technologies Inc.
The First Script
first-script.html
168
<html>
<body>
<script type="text/javascript">
alert('Hello JavaScript!');
</script>
</body>
</html>
ยฉ Sun Technologies Inc.
Another Small Example
small-example.html
169
<html>
<body>
<script type="text/javascript">
document.write('JavaScript rulez!');
</script>
</body>
</html>
ยฉ Sun Technologies Inc.
Using JavaScript Code
โ€ข The JavaScript code can be placed in:
โ€ข <script> tag in the head
โ€ข <script> tag in the body โ€“ not recommended
โ€ข External files, linked via <script> tag the head
โ€ข Files usually have .js extension
โ€ข Highly recommended
โ€ข The .js files get cached by the browser
170
<script src="scripts.js" type="text/javscript">
<!โ€“ code placed here will not be executed! -->
</script>
ยฉ Sun Technologies Inc.
JavaScript โ€“ When is Executed?
โ€ข JavaScript code is executed during the page loading or when the
browser fires an event
โ€ข All statements are executed at page loading
โ€ข Some statements just define functions that can be called later
โ€ข Function calls or code can be attached as "event handlers" via tag
attributes
โ€ข Executed when the event is fired by the browser
171
<img src="logo.gif" onclick="alert('clicked!')" />
ยฉ Sun Technologies Inc.
<html>
<head>
<script type="text/javascript">
function test (message) {
alert(message);
}
</script>
</head>
<body>
<img src="logo.gif"
onclick="test('clicked!')" />
</body>
</html>
Calling a JavaScript Function from
Event Handler โ€“ Example
image-onclick.html
172ยฉ Sun Technologies Inc.
Using External Script Files
โ€ขUsing external script files:
โ€ขExternal JavaScript file:
173
<html>
<head>
<script src="sample.js" type="text/javascript">
</script>
</head>
<body>
<button onclick="sample()" value="Call JavaScript
function from sample.js" />
</body>
</html>
function sample() {
alert('Hello from sample.js!')
}
external-
JavaScript.html
sample.js
The <script> tag is always
empty.
ยฉ Sun Technologies Inc.
The JavaScript
Syntax
JavaScript Syntax
โ€ข The JavaScript syntax is similar to C# and Java
โ€ข Operators (+, *, =, !=, &&, ++, โ€ฆ)
โ€ข Variables (typeless)
โ€ข Conditional statements (if, else)
โ€ข Loops (for, while)
โ€ข Arrays (my_array[]) and associative arrays (my_array['abc'])
โ€ข Functions (can return value)
โ€ข Function variables (like the C# delegates)
175ยฉ Sun Technologies Inc.
Data Types
โ€ข JavaScript data types:
โ€ข Numbers (integer, floating-point)
โ€ข Boolean (true / false)
โ€ข String type โ€“ string of characters
โ€ข Arrays
โ€ข Associative arrays (hash tables)
176
var myName = "You can use both single or double
quotes for strings";
var my_array = [1, 5.3, "aaa"];
var my_hash = {a:2, b:3, c:"text"};
ยฉ Sun Technologies Inc.
Everything is Object
โ€ข Every variable can be considered as object
โ€ข For example strings and arrays have member functions:
177
var test = "some string";
alert(test[7]); // shows letter 'r'
alert(test.charAt(5)); // shows letter 's'
alert("test".charAt(1)); //shows letter 'e'
alert("test".substring(1,3)); //shows 'es'
var arr = [1,3,4];
alert (arr.length); // shows 3
arr.push(7); // appends 7 to end of array
alert (arr[3]); // shows 7
objects.html
ยฉ Sun Technologies Inc.
String Operations
โ€ข The + operator joins strings
โ€ข What is "9" + 9?
โ€ข Converting string to number:
178
string1 = "fat ";
string2 = "cats";
alert(string1 + string2); // fat cats
alert("9" + 9); // 99
alert(parseInt("9") + 9); // 18
ยฉ Sun Technologies Inc.
Arrays Operations and
Properties
โ€ขDeclaring new empty array:
โ€ขDeclaring an array holding few elements:
โ€ขAppending an element / getting the last element:
โ€ขReading the number of elements (array length):
โ€ขFinding element's index in the array:
179
var arr = new Array();
var arr = [1, 2, 3, 4, 5];
arr.push(3);
var element = arr.pop();
arr.length;
arr.indexOf(1);
ยฉ Sun Technologies Inc.
Standard Popup Boxes
โ€ข Alert box with text and [OK] button
โ€ข Just a message shown in a dialog box:
โ€ข Confirmation box
โ€ข Contains text, [OK] button and [Cancel] button:
โ€ข Prompt box
โ€ข Contains text, input field with default value:
180
alert("Some text here");
confirm("Are you sure?");
prompt ("enter amount", 10);
ยฉ Sun Technologies Inc.
Sum of Numbers โ€“ Example
sum-of-numbers.html
181
<html>
<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>
ยฉ Sun Technologies Inc.
Sum of Numbers โ€“ Example (2)
sum-of-numbers.html (cont.)
182
<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>
ยฉ Sun Technologies Inc.
JavaScript Prompt โ€“ Example
prompt.html
183
price = prompt("Enter the price", "10.00");
alert('Price + VAT = ' + price * 1.2);
ยฉ Sun Technologies Inc.
Greater than
<=
Symbo
l
Meaning
>
< Less than
>= Greater than or equal
to
Less than or equal to
== Equal
!= Not equal
Conditional Statement (if)
184
unitPrice = 1.30;
if (quantity > 100) {
unitPrice = 1.20;
}
ยฉ Sun Technologies Inc.
Conditional Statement (if) (2)
โ€ขThe condition may be of Boolean or integer type:
185
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 + ";");
}
conditional-statements.html
ยฉ Sun Technologies Inc.
Switch Statement
โ€ข The switch statement works like in C#:
186
switch (variable) {
case 1:
// do something
break;
case 'a':
// do something else
break;
case 3.14:
// another code
break;
default:
// something completely different
}
switch-statements.html
ยฉ Sun Technologies Inc.
Loops
โ€ข Like in C#
โ€ข for loop
โ€ข while loop
โ€ข do โ€ฆ while loop
187
var counter;
for (counter=0; counter<4; counter++) {
alert(counter);
}
while (counter < 5) {
alert(++counter);
}
loops.html
ยฉ Sun Technologies Inc.
Functions
โ€ข Code structure โ€“ splitting code into parts
โ€ข Data comes in, processed, result returned
188
function average(a, b, c)
{
var total;
total = a+b+c;
return total/3;
}
Parameters come
in here.
Declaring
variables is
optional. Type is
never declared.
Value returned
here.
ยฉ Sun Technologies Inc.
Function Arguments
and Return Value
โ€ข Functions are not required to return a value
โ€ข When calling function it is not obligatory to specify all of its arguments
โ€ขThe function has access to all the arguments passed via
arguments array
189
function sum() {
var sum = 0;
for (var i = 0; i < arguments.length; i ++)
sum += parseInt(arguments[i]);
return sum;
}
alert(sum(1, 2, 4));
functions-demo.html
ยฉ Sun Technologies Inc.
Document Object
Model (DOM)
Document Object Model (DOM)
โ€ขEvery HTML element is accessible via the
JavaScript DOM API
โ€ขMost DOM objects can be manipulated by
the programmer
โ€ขThe event model lets a document to react
when the user does something on the page
โ€ขAdvantages
โ€ขCreate interactive pages
โ€ขUpdates the objects of a page without
reloading it
191ยฉ Sun Technologies Inc.
Accessing Elements
โ€ข Access elements via their ID attribute
โ€ข Via the name attribute
โ€ข Via tag name
โ€ข Returns array of descendant <img> elements of the element "el"
192
var elem = document.getElementById("some_id")
var arr = document.getElementsByName("some_name")
var imgTags = el.getElementsByTagName("img")
ยฉ Sun Technologies Inc.
DOM Manipulation
โ€ข Once we access an element, we can read and write its
attributes
193
function change(state) {
var lampImg = document.getElementById("lamp");
lampImg.src = "lamp_" + state + ".png";
var statusDiv =
document.getElementById("statusDiv");
statusDiv.innerHTML = "The lamp is " + state";
}
โ€ฆ
<img src="test_on.gif" onmouseover="change('off')"
onmouseout="change('on')" />
DOM-manipulation.html
ยฉ Sun Technologies Inc.
Common Element Properties
โ€ข Most of the properties are derived from the HTML attributes of the tag
โ€ข E.g. id, name, href, alt, title, src, etcโ€ฆ
โ€ข style property โ€“ allows modifying the CSS styles of the element
โ€ข Corresponds to the inline style of the element
โ€ข Not the properties derived from embedded or external CSS rules
โ€ข Example: style.width, style.marginTop, style.backgroundImage
194ยฉ Sun Technologies Inc.
Common Element Properties (2)
โ€ข className โ€“ the class attribute of the tag
โ€ข innerHTML โ€“ holds all the entire HTML code inside the element
โ€ข Read-only properties with information for the current element and its
state
โ€ข tagName, offsetWidth, offsetHeight, scrollHeight, scrollTop, nodeType, etcโ€ฆ
195ยฉ Sun Technologies Inc.
Accessing Elements through the
DOM Tree Structure
โ€ข We can access elements in the DOM through some tree manipulation
properties:
โ€ข element.childNodes
โ€ข element.parentNode
โ€ข element.nextSibling
โ€ข element.previousSibling
โ€ข element.firstChild
โ€ข element.lastChild
196ยฉ Sun Technologies Inc.
Accessing Elements through the
DOM Tree โ€“ Example
๏‚ฎ Warning: may not return what you expected
due to Browser differences
197
var el = document.getElementById('div_tag');
alert (el.childNodes[0].value);
alert (el.childNodes[1].
getElementsByTagName('span').id);
โ€ฆ
<div id="div_tag">
<input type="text" value="test text" />
<div>
<span id="test">test span</span>
</div>
</div>
accessing-elements-demo.html
ยฉ Sun Technologies Inc.
The HTML DOM
Event Model
The HTML DOM Event Model
โ€ข JavaScript can register event handlers
โ€ข Events are fired by the Browser and are sent to the specified JavaScript event
handler function
โ€ข Can be set with HTML attributes:
โ€ข Can be accessed through the DOM:
199
<img src="test.gif" onclick="imageClicked()" />
var img = document.getElementById("myImage");
img.onclick = imageClicked;
ยฉ Sun Technologies Inc.
The HTML DOM Event Model (2)
โ€ข All event handlers receive one parameter
โ€ข It brings information about the event
โ€ข Contains the type of the event (mouse click, key press, etc.)
โ€ข Data about the location where the event has been fired (e.g. mouse
coordinates)
โ€ข Holds a reference to the event sender
โ€ข E.g. the button that was clicked
200ยฉ Sun Technologies Inc.
The HTML DOM Event Model (3)
โ€ข Holds information about the state of [Alt], [Ctrl] and [Shift] keys
โ€ข Some browsers do not send this object, but place it in the
document.event
โ€ข Some of the names of the eventโ€™s object properties are browser-
specific
201
ยฉ Sun Technologies Inc.
Common DOM Events
โ€ข Mouse events:
โ€ข onclick, onmousedown, onmouseup
โ€ข onmouseover, onmouseout, onmousemove
โ€ข Key events:
โ€ข onkeypress, onkeydown, onkeyup
โ€ข Only for input fields
โ€ข Interface events:
โ€ข onblur, onfocus
โ€ข onscroll
ยฉ Sun Technologies Inc.
Common DOM Events (2)
โ€ข Form events
โ€ข onchange โ€“ for input fields
โ€ข onsubmit
โ€ข Allows you to cancel a form submission
โ€ข Useful for form validation
โ€ข Miscellaneous events
โ€ข onload, onunload
โ€ข Allowed only for the <body> element
โ€ข Fires when all content on the page was loaded / unloaded
203ยฉ Sun Technologies Inc.
onload Event โ€“ Example
โ€ข onload event
204
<html>
<head>
<script type="text/javascript">
function greet() {
alert("Loaded.");
}
</script>
</head>
<body onload="greet()" >
</body>
</html>
onload.html
ยฉ Sun Technologies Inc.
The Built-In
Browser Objects
Built-in Browser Objects
โ€ข The browser provides some read-only data via:
โ€ข window
โ€ข The top node of the DOM tree
โ€ข Represents the browser's window
โ€ข document
โ€ข holds information the current loaded document
โ€ข screen
โ€ข Holds the userโ€™s display properties
โ€ข browser
โ€ข Holds information about the browser
206ยฉ Sun Technologies Inc.
DOM Hierarchy โ€“ Example
207
window
navigator screen document history location
form
button form
form
ยฉ Sun Technologies Inc.
Opening New Window โ€“ Example
โ€ข window.open()
208
var newWindow = window.open("", "sampleWindow",
"width=300, height=100, menubar=yes,
status=yes, resizable=yes");
newWindow.document.write(
"<html><head><title>
Sample Title</title>
</head><body><h1>Sample
Text</h1></body>");
newWindow.status =
"Hello folks";
window-open.html
ยฉ Sun Technologies Inc.
The Navigator Object
209
alert(window.navigator.userAgent);
The navigator in
the browser
window
The
userAgent
(browser ID)
The
browser
window
ยฉ Sun Technologies Inc.
The Screen Object
โ€ข The screen object contains information about the display
210
window.moveTo(0, 0);
x = screen.availWidth;
y = screen.availHeight;
window.resizeTo(x, y);
ยฉ Sun Technologies Inc.
Document and Location
โ€ข document object
โ€ข Provides some built-in arrays of specific
objects on the currently loaded Web page
โ€ข document.location
โ€ข Used to access the currently open URL or redirect the browser
211
document.links[0].href = "yahoo.com";
document.write(
"This is some <b>bold text</b>");
document.location = "http://www.yahoo.com/";
ยฉ Sun Technologies Inc.
Form Validation โ€“ Example
212
function checkForm()
{
var valid = true;
if (document.mainForm.firstName.value == "") {
alert("Please type in your first name!");
document.getElementById("firstNameError").
style.display = "inline";
valid = false;
}
return valid;
}
โ€ฆ
<form name="mainForm" onsubmit="return checkForm()">
<input type="text" name="firstName" />
โ€ฆ
</form>
form-validation.html
ยฉ Sun Technologies Inc.
The Math Object
โ€ข The Math object provides some mathematical functions
213
for (i=1; i<=20; i++) {
var x = Math.random();
x = 10*x + 1;
x = Math.floor(x);
document.write(
"Random number (" +
i + ") in range " +
"1..10 --> " + x +
"<br/>");
}
math.html
ยฉ Sun Technologies Inc.
The Date Object
โ€ข The Date object provides date / calendar functions
214
var now = new Date();
var result = "It is now " + now;
document.getElementById("timeField")
.innerText = result;
...
<p id="timeField"></p>
dates.html
ยฉ Sun Technologies Inc.
Timers: setTimeout()
โ€ข Make something happen (once) after a fixed delay
215
var timer = setTimeout('bang()', 5000);
clearTimeout(timer);
5 seconds after this
statement executes, this
function is called
Cancels the
timer
ยฉ Sun Technologies Inc.
Timers: setInterval()
โ€ข Make something happen repeatedly at fixed intervals
216
var timer = setInterval('clock()', 1000);
clearInterval(timer);
This function is called
continuously per 1
second.
Stop the
timer.
ยฉ Sun Technologies Inc.
Timer โ€“ Example
217
<script type="text/javascript">
function timerFunc() {
var now = new Date();
var hour = now.getHours();
var min = now.getMinutes();
var sec = now.getSeconds();
document.getElementById("clock").value =
"" + hour + ":" + min + ":" + sec;
}
setInterval('timerFunc()', 1000);
</script>
<input type="text" id="clock" />
timer-demo.html
ยฉ Sun Technologies Inc.
Debugging JavaScript
Debugging JavaScript
โ€ข Modern browsers have JavaScript console where errors in
scripts are reported
โ€ข Errors may differ across browsers
โ€ข Several tools to debug JavaScript
โ€ข Microsoft Script Editor
โ€ข Add-on for Internet Explorer
โ€ข Supports breakpoints, watches
โ€ข JavaScript statement debugger; opens the script editor
219ยฉ Sun Technologies Inc.
Firebug
โ€ข Firebug โ€“ Firefox add-on for debugging JavaScript, CSS, HTML
โ€ข Supports breakpoints, watches, JavaScript console editor
โ€ข Very useful for CSS and HTML too
โ€ข You can edit all the document real-time: CSS, HTML, etc
โ€ข Shows how CSS rules apply to element
โ€ข Shows Ajax requests and responses
โ€ข Firebug is written mostly in JavaScript
220ยฉ Sun Technologies Inc.
Firebug (2)
221ยฉ Sun Technologies Inc.
JavaScript Console Object
โ€ข The console object exists only if there is a debugging tool that
supports it
โ€ข Used to write log messages at runtime
โ€ข Methods of the console object:
โ€ข debug(message)
โ€ข info(message)
โ€ข log(message)
โ€ข warn(message)
โ€ข error(message)
222ยฉ Sun Technologies Inc.
HTML, CSS and JavaScript Basics
Questions?
ยฉ Sun Technologies Inc. 223

More Related Content

What's hot (20)

PPTX
(Fast) Introduction to HTML & CSS
Dave Kelly
ย 
PPTX
html-css
Dhirendra Chauhan
ย 
PPT
CSS Introduction
Swati Sharma
ย 
PDF
Introduction to HTML5
Gil Fink
ย 
PPTX
Complete Lecture on Css presentation
Salman Memon
ย 
PDF
Basic-CSS-tutorial
tutorialsruby
ย 
PPTX
Event In JavaScript
ShahDhruv21
ย 
PPTX
Cascading style sheets (CSS)
Harshita Yadav
ย 
PPT
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
ย 
PPTX
html-table
Dhirendra Chauhan
ย 
PPTX
Basic HTML
Sayan De
ย 
PDF
HTML5: features with examples
Alfredo Torre
ย 
PDF
Frontend Crash Course: HTML and CSS
Thinkful
ย 
PPT
Html & Css presentation
joilrahat
ย 
PDF
Introduction to HTML and CSS
Mario Hernandez
ย 
PDF
Introduction to HTML
Seble Nigussie
ย 
PPTX
Java script arrays
Frayosh Wadia
ย 
PPTX
Html and css presentation
umesh patil
ย 
PPTX
CSS
People Strategists
ย 
(Fast) Introduction to HTML & CSS
Dave Kelly
ย 
html-css
Dhirendra Chauhan
ย 
CSS Introduction
Swati Sharma
ย 
Introduction to HTML5
Gil Fink
ย 
Complete Lecture on Css presentation
Salman Memon
ย 
Basic-CSS-tutorial
tutorialsruby
ย 
Event In JavaScript
ShahDhruv21
ย 
Cascading style sheets (CSS)
Harshita Yadav
ย 
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
ย 
html-table
Dhirendra Chauhan
ย 
Basic HTML
Sayan De
ย 
HTML5: features with examples
Alfredo Torre
ย 
Frontend Crash Course: HTML and CSS
Thinkful
ย 
Html & Css presentation
joilrahat
ย 
Introduction to HTML and CSS
Mario Hernandez
ย 
Introduction to HTML
Seble Nigussie
ย 
Java script arrays
Frayosh Wadia
ย 
Html and css presentation
umesh patil
ย 

Viewers also liked (14)

PDF
Rencontre du CRIPS / Act Up-Paris "Personnes trans : quels enjeux de santรฉ ?"...
Santรฉ des trans
ย 
PDF
Systรจme de gestion de tickets
raymen87
ย 
PPTX
Javascript as a first programming language : votre IC prรชte pour la rรฉvolution !
VISEO
ย 
PDF
Jsp
raymen87
ย 
PPS
ArลŸivlik FotoฤŸraflar
Holistik DanฤฑลŸmanlฤฑk Hiz. Ltd.ลžti.
ย 
PPTX
Cascading Style Sheets - CSS
Sun Technlogies
ย 
PDF
Les Applications CRM mobile Tunisie Telecom Pour BlackBerry
tunisieblackberry
ย 
PDF
Tutoriel java
Kalilou DIABY
ย 
PDF
Html 5 in a big nutshell
Lennart Schoors
ย 
PDF
Rapport PFE "Conception et dรฉveloppement d'un Portail web pour le Smart Met...
Hajer Dahech
ย 
PDF
Up to Speed on HTML 5 and CSS 3
M. Jackson Wilkinson
ย 
PPT
Html Ppt
vijayanit
ย 
PDF
HTML CSS Basics
Mai Moustafa
ย 
PDF
Html / CSS Presentation
Shawn Calvert
ย 
Rencontre du CRIPS / Act Up-Paris "Personnes trans : quels enjeux de santรฉ ?"...
Santรฉ des trans
ย 
Systรจme de gestion de tickets
raymen87
ย 
Javascript as a first programming language : votre IC prรชte pour la rรฉvolution !
VISEO
ย 
Jsp
raymen87
ย 
Cascading Style Sheets - CSS
Sun Technlogies
ย 
Les Applications CRM mobile Tunisie Telecom Pour BlackBerry
tunisieblackberry
ย 
Tutoriel java
Kalilou DIABY
ย 
Html 5 in a big nutshell
Lennart Schoors
ย 
Rapport PFE "Conception et dรฉveloppement d'un Portail web pour le Smart Met...
Hajer Dahech
ย 
Up to Speed on HTML 5 and CSS 3
M. Jackson Wilkinson
ย 
Html Ppt
vijayanit
ย 
HTML CSS Basics
Mai Moustafa
ย 
Html / CSS Presentation
Shawn Calvert
ย 
Ad

Similar to HTML, CSS and Java Scripts Basics (20)

PPTX
HyperText Markup Language - HTML
Sun Technlogies
ย 
PPTX
HTML Basic, CSS Basic, JavaScript basic.
Beqa Chacha
ย 
PPTX
4. html css-java script-basics
Nikita Garg
ย 
PPTX
4. html css-java script-basics
Minea Chem
ย 
PPTX
4. html css-java script-basics
xu fag
ย 
PPTX
POLITEKNIK MALAYSIA
Aiman Hud
ย 
PPTX
Additional HTML
Doeun KOCH
ย 
PPTX
HTML web design_ an introduction to design
SureshSingh142
ย 
PDF
02 HTML-01.pdf
EshaYasir1
ย 
PPTX
Html css java script basics All about you need
Dipen Parmar
ย 
PPTX
HTML CSS by Anubhav Singh
Anubhav659
ย 
PPT
Html basics
mcatahir947
ย 
PDF
Html tutorial
NAGARAJU MAMILLAPALLY
ย 
PPTX
3 1-html-fundamentals-110302100520-phpapp02
Aditya Varma
ย 
PPTX
HTML Fundamentals
BG Java EE Course
ย 
PPT
Eye catching HTML BASICS tips: Learn easily
shabab shihan
ย 
PPTX
Introduction to HTML Communication Skills
GraceChokoli1
ย 
PDF
What is HTML - An Introduction to HTML (Hypertext Markup Language)
Ahsan Rahim
ย 
HyperText Markup Language - HTML
Sun Technlogies
ย 
HTML Basic, CSS Basic, JavaScript basic.
Beqa Chacha
ย 
4. html css-java script-basics
Nikita Garg
ย 
4. html css-java script-basics
Minea Chem
ย 
4. html css-java script-basics
xu fag
ย 
POLITEKNIK MALAYSIA
Aiman Hud
ย 
Additional HTML
Doeun KOCH
ย 
HTML web design_ an introduction to design
SureshSingh142
ย 
02 HTML-01.pdf
EshaYasir1
ย 
Html css java script basics All about you need
Dipen Parmar
ย 
HTML CSS by Anubhav Singh
Anubhav659
ย 
Html basics
mcatahir947
ย 
Html tutorial
NAGARAJU MAMILLAPALLY
ย 
3 1-html-fundamentals-110302100520-phpapp02
Aditya Varma
ย 
HTML Fundamentals
BG Java EE Course
ย 
Eye catching HTML BASICS tips: Learn easily
shabab shihan
ย 
Introduction to HTML Communication Skills
GraceChokoli1
ย 
What is HTML - An Introduction to HTML (Hypertext Markup Language)
Ahsan Rahim
ย 
Ad

More from Sun Technlogies (17)

PPTX
Silk Performer Presentation v1
Sun Technlogies
ย 
PPT
Selenium
Sun Technlogies
ย 
PPTX
Selenium web driver
Sun Technlogies
ย 
PPTX
XPATH
Sun Technlogies
ย 
PPTX
Path Testing
Sun Technlogies
ย 
PPTX
Maven and ANT
Sun Technlogies
ย 
PPTX
Jmeter
Sun Technlogies
ย 
PPTX
Jira
Sun Technlogies
ย 
PPTX
Javascript
Sun Technlogies
ย 
PPTX
Extended Finite State Machine - EFSM
Sun Technlogies
ย 
PPTX
Core java
Sun Technlogies
ย 
PPTX
Automation Testing
Sun Technlogies
ย 
PPTX
Devops
Sun Technlogies
ย 
PPTX
QTest
Sun Technlogies
ย 
PPTX
Mobile Application Testing
Sun Technlogies
ย 
PPTX
Array and functions
Sun Technlogies
ย 
PPTX
Sikuli
Sun Technlogies
ย 
Silk Performer Presentation v1
Sun Technlogies
ย 
Selenium
Sun Technlogies
ย 
Selenium web driver
Sun Technlogies
ย 
XPATH
Sun Technlogies
ย 
Path Testing
Sun Technlogies
ย 
Maven and ANT
Sun Technlogies
ย 
Jmeter
Sun Technlogies
ย 
Javascript
Sun Technlogies
ย 
Extended Finite State Machine - EFSM
Sun Technlogies
ย 
Core java
Sun Technlogies
ย 
Automation Testing
Sun Technlogies
ย 
Devops
Sun Technlogies
ย 
QTest
Sun Technlogies
ย 
Mobile Application Testing
Sun Technlogies
ย 
Array and functions
Sun Technlogies
ย 
Sikuli
Sun Technlogies
ย 

Recently uploaded (20)

PPTX
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
ย 
PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
ย 
DOCX
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
ย 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
PDF
Which Hiring Management Tools Offer the Best ROI?
HireME
ย 
PPTX
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
ย 
PDF
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
ย 
DOCX
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
ย 
PPTX
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
ย 
PPTX
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
ย 
PPTX
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
ย 
PDF
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
ย 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
PDF
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
ย 
PDF
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
ย 
PDF
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
ย 
PDF
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
ย 
PDF
Rewards and Recognition (2).pdf
ethan Talor
ย 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
PPTX
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
ย 
Wondershare Filmora Crack 14.5.18 + Key Full Download [Latest 2025]
HyperPc soft
ย 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
ย 
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
ย 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
Which Hiring Management Tools Offer the Best ROI?
HireME
ย 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
ย 
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
ย 
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
ย 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
ย 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
ย 
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
ย 
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
ย 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
ย 
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
ย 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
ย 
IObit Uninstaller Pro 14.3.1.8 Crack for Windows Latest
utfefguu
ย 
Rewards and Recognition (2).pdf
ethan Talor
ย 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
ย 

HTML, CSS and Java Scripts Basics

  • 1. HTML Basics HTML, Text, Images, Tables
  • 2. Table of Contents ยฉ Sun Technologies Inc. 2 1. Introduction to HTML How the Web Works? What is a Web Page? My First HTML Page Basic Tags: Hyperlinks, Images, Formatting Headings and Paragraphs 2. HTML in Details The <!DOCTYPE> Declaration The <head> Section: Title, Meta, Script, Style
  • 3. Table of Contents (2) ยฉ Sun Technologies Inc. 3 2. HTML in Details โ€ข The <body> Section โ€ข Text Styling and Formatting Tags โ€ข Hyperlinks: <a>, Hyperlinks and Sections โ€ข Images: <img> โ€ข Lists: <ol>, <ul> and <dl> 3. The <div> and <span> elements 4. HTML Tables 5. HTML Forms
  • 4. How the Web Works? โ€ข WWW use classical client / server architecture โ€ข HTTP is text-based request-response protocol 4 Page request Client running a Web Browser Server running Web Server Software (IIS, Apache, etc.) Server response HTTP HTTP ยฉ Sun Technologies Inc.
  • 5. What is a Web Page? โ€ข Web pages are text files containing HTML โ€ข HTML โ€“ Hyper Text Markup Language โ€ข A notation for describing โ€ข document structure (semantic markup) โ€ข formatting (presentation markup) โ€ข The markup tags provide information about the page content structure 5ยฉ Sun Technologies Inc.
  • 6. Creating HTML Pages โ€ข An HTML file must have an .htm or .html file extension โ€ข HTML files can be created with text editors: โ€ข NotePad, NotePad ++, PSPad โ€ข Or HTML editors (WYSIWYG Editors): โ€ข Microsoft FrontPage โ€ข Macromedia Dreamweaver โ€ข Netscape Composer โ€ข Microsoft Word โ€ข Visual Studio 6ยฉ Sun Technologies Inc.
  • 8. HTML Structure โ€ขHTML is comprised of โ€œelementsโ€ and โ€œtagsโ€ โ€ขBegins with <html> and ends with </html> โ€ขElements (tags) are nested one inside another: โ€ขTags have attributes: โ€ขHTML describes structure using two main sections: <head> and <body> 8 <html> <head></head> <body></body> </html> <img src="logo.jpg" alt="logo" /> ยฉ Sun Technologies Inc.
  • 9. HTML Code Formatting โ€ขThe HTML source code should be formatted to increase readability and facilitate debugging. โ€ขEvery block element should start on a new line. โ€ขEvery nested (block) element should be indented. โ€ขBrowsers ignore multiple whitespaces in the page source, so formatting is harmless. โ€ข For performance reasons, formatting can be sacrificed ยฉ Sun Technologies Inc. 9
  • 10. First HTML Page 10 <!DOCTYPE HTML> <html> <head> <title>My First HTML Page</title> </head> <body> <p>This is some text...</p> </body> </html> test.html ยฉ Sun Technologies Inc.
  • 11. <!DOCTYPE HTML> <html> <head> <title>My First HTML Page</title> </head> <body> <p>This is some text...</p> </body> </html> First HTML Page: Tags 11 Opening tag Closing tag An HTML element consists of an opening tag, a closing tag and the content inside. ยฉ Sun Technologies Inc.
  • 12. <!DOCTYPE HTML> <html> <head> <title>My First HTML Page</title> </head> <body> <p>This is some text...</p> </body> </html> First HTML Page: Header 12 HTML header ยฉ Sun Technologies Inc.
  • 13. <!DOCTYPE HTML> <html> <head> <title>My First HTML Page</title> </head> <body> <p>This is some text...</p> </body> </html> First HTML Page: Body ยฉ Sun Technologies Inc. 13 HTML body
  • 14. Some Simple Tags โ€ข Hyperlink Tags โ€ข Image Tags โ€ข Text formatting tags ยฉ Sun Technologies Inc. 14 <a href="http://www.telerik.com/" title="Telerik">Link to Telerik Web site</a> <img src="logo.gif" alt="logo" /> This text is <em>emphasized.</em> <br />new line<br /> This one is <strong>more emphasized.</strong>
  • 15. Some Simple Tags โ€“ Example ยฉ Sun Technologies Inc. 15 <!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> some-tags.html
  • 16. Some Simple Tags โ€“ Example (2) 16 <!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> some-tags.html ยฉ Sun Technologies Inc.
  • 17. Tags Attributes โ€ข Tags can have attributes โ€ข Attributes specify properties and behavior โ€ข Example: โ€ข Few attributes can apply to every element: โ€ข id, style, class, title โ€ข The id is unique in the document โ€ข Content of title attribute is displayed as hint when the element is hovered with the mouse โ€ข Some elements have obligatory attributes 17 <img src="logo.gif" alt="logo" /> Attribute alt with value "logo" ยฉ Sun Technologies Inc.
  • 18. Headings and Paragraphs โ€ข Heading Tags (h1 โ€“ h6) โ€ข Paragraph Tags โ€ข Sections: div and span 18 <p>This is my first paragraph</p> <p>This is my second paragraph</p> <h1>Heading 1</h1> <h2>Sub heading 2</h2> <h3>Sub heading 3</h3> <div style="background: skyblue;"> This is a div</div> ยฉ Sun Technologies Inc.
  • 19. Headings and Paragraphs โ€“ Example 19 <!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> headings.html ยฉ Sun Technologies Inc.
  • 20. <!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> Headings and Paragraphs โ€“ Example (2) 20 headings.html ยฉ Sun Technologies Inc.
  • 21. Introduction to HTML HTML Document Structure in Depth
  • 22. Preface โ€ข It is important to have the correct vision and attitude towards HTML โ€ข HTML is only about structure, not appearance โ€ข Browsers tolerate invalid HTML code and parse errors โ€“ you should not. 22ยฉ Sun Technologies Inc.
  • 23. 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: โ€ขSee http://w3.org/QA/2002/04/valid-dtd-list.html for a list of possible doctypes 23 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ยฉ Sun Technologies Inc.
  • 24. The <head> Section โ€ข Contains information that doesnโ€™t show directly on the viewable page โ€ข Starts after the <!doctype> declaration โ€ข Begins with <head> and ends with </head> โ€ข Contains mandatory single <title> tag โ€ข Can contain some other tags, e.g. โ€ข<meta> โ€ข<script> โ€ข<style> โ€ข<!โ€“- comments --> 24ยฉ Sun Technologies Inc.
  • 25. <head> Section: <title> tag โ€ขTitle should be placed between <head> and </head> tags โ€ขUsed to specify a title in the window title bar โ€ขSearch engines and people rely on titles 25 <title>Telerik Academy โ€“ Winter Season 2009/2010 </title> ยฉ Sun Technologies Inc.
  • 26. <head> Section: <meta> โ€ข Meta tags additionally describe the content contained within the page 26 <meta name="description" content="HTML tutorial" /> <meta name="keywords" content="html, web design, styles" /> <meta name="author" content="Chris Brewer" /> <meta http-equiv="refresh" content="5; url=http://www.telerik.com" /> ยฉ Sun Technologies Inc.
  • 27. <head> Section: <script> โ€ข The <script> element is used to embed scripts into an HTML document โ€ข Script are executed in the client's Web browser โ€ข Scripts can live in the <head> and in the <body> sections โ€ข Supported client-side scripting languages: โ€ข JavaScript (it is not Java!) โ€ข VBScript โ€ข JScript 27ยฉ Sun Technologies Inc.
  • 28. The <script> Tag โ€“ Example 28 <!DOCTYPE HTML> <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> scripts-example.html ยฉ Sun Technologies Inc.
  • 29. <head> Section: <style> โ€ขThe <style> element embeds formatting information (CSS styles) into an HTML page 29 <html> <head> <style type="text/css"> p { font-size: 12pt; line-height: 12pt; } p:first-letter { font-size: 200%; } span { text-transform: uppercase; } </style> </head> <body> <p>Styles demo.<br /> <span>Test uppercase</span>. </p> </body> </html> style-example.html ยฉ Sun Technologies Inc.
  • 30. Comments: <!-- --> Tag โ€ข Comments can exist anywhere between the <html></html> tags โ€ข Comments start with <!-- and end with --> 30 <!โ€“- Telerik Logo (a JPG file) --> <img src="logo.jpg" alt=โ€œTelerik Logo"> <!โ€“- Hyperlink to the web site --> <a href="http://telerik.com/">Telerik</a> <!โ€“- Show the news table --> <table class="newstable"> ... ยฉ Sun Technologies Inc.
  • 31. <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 </body> 31 <html> <head><title>Test page</title></head> <body> <!-- This is the Web page body --> </body> </html> ยฉ Sun Technologies Inc.
  • 32. Text Formatting โ€ข Text formatting tags modify the text between the opening tag and the closing tag โ€ข Ex. <b>Hello</b> makes โ€œHelloโ€ bold <b></b> bold <i></i> italicized <u></u> underlined <sup></sup> Samplesuperscript <sub></sub> Samplesubscript <strong></strong> strong <em></em> emphasized <pre></pre> Preformatted text <blockquote></blockquote> Quoted text block <del></del> Deleted text โ€“ strike through 32 ยฉ Sun Technologies Inc.
  • 33. Text Formatting โ€“ Example 33 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Page Title</title> </head> <body> <h1>Notice</h1> <p>This is a <em>sample</em> Web page.</p> <p><pre>Next paragraph: preformatted.</pre></p> <h2>More Info</h2> <p>Specifically, weโ€™re using XHMTL 1.0 transitional.<br /> Next line.</p> </body> </html> text-formatting.html ยฉ Sun Technologies Inc.
  • 34. Text Formatting โ€“ Example (2) 34 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Page Title</title> </head> <body> <h1>Notice</h1> <p>This is a <em>sample</em> Web page.</p> <p><pre>Next paragraph: preformatted.</pre></p> <h2>More Info</h2> <p>Specifically, weโ€™re using XHMTL 1.0 transitional.<br /> Next line.</p> </body> </html> text-formatting.html ยฉ Sun Technologies Inc.
  • 35. Hyperlinks: <a> Tag โ€ข Link to a document called form.html on the same server in the same directory: โ€ข Link to a document called parent.html on the same server in the parent directory: โ€ข Link to a document called cat.html on the same server in the subdirectory stuff: 35 <a href="form.html">Fill Our Form</a> <a href="../parent.html">Parent</a> <a href="stuff/cat.html">Catalog</a> ยฉ Sun Technologies Inc.
  • 36. Hyperlinks: <a> Tag (2) โ€ข Link to an external Web site: โ€ข Always use a full URL, including "http://", not just "www.somesite.com" โ€ข Using the target="_blank" attribute opens the link in a new window โ€ข Link to an e-mail address: 36 <a href="http://www.devbg.org" target="_blank">BASD</a> <a href="mailto:bugs@example.com?subject=Bug+Report"> Please report bugs here (by e-mail only)</a> ยฉ Sun Technologies Inc.
  • 37. Hyperlinks: <a> Tag (3) โ€ข Link to a document called apply-now.html โ€ขOn the same server, in same directory โ€ขUsing an image as a link button: โ€ข Link to a document called index.html โ€ขOn the same server, in the subdirectory english of the parent directory: 37 <a href="apply-now.html"><img src="apply-now-button.jpg" /></a> <a href="../english/index.html">Switch to English version</a> ยฉ Sun Technologies Inc.
  • 38. Hyperlinks and Sections โ€ขLink to another location in the same document: โ€ขLink to a specific location in another document: 38 <a href="#section1">Go to Introduction</a> ... <h2 id="section1">Introduction</h2> <a href="chapter3.html#section3.1.1">Go to Section 3.1.1</a> <!โ€“- In chapter3.html --> ... <div id="section3.1.1"> <h3>3.1.1. Technical Background</h3> </div> ยฉ Sun Technologies Inc.
  • 39. Hyperlinks โ€“ Example 39 <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-now-button.jpgโ€ /></a> <br /> <a href="../english/index.html">Switch to English version</a> <br /> hyperlinks.html ยฉ Sun Technologies Inc.
  • 40. <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-now-button.jpgโ€ /></a> <br /> <a href="../english/index.html">Switch to English version</a> <br /> hyperlinks.html Hyperlinks โ€“ Example (2) 40ยฉ Sun Technologies Inc.
  • 41. Links to the Same Document โ€“ Example 41 <h1>Table of Contents</h1> <p><a href="#section1">Introduction</a><br /> <a href="#section2">Some background</A><br /> <a href="#section2.1">Project History</a><br /> ...the rest of the table of contents... <!-- The document text follows here --> <h2 id="section1">Introduction</h2> ... Section 1 follows here ... <h2 id="section2">Some background</h2> ... Section 2 follows here ... <h3 id="section2.1">Project History</h3> ... Section 2.1 follows here ... links-to-same-document.html ยฉ Sun Technologies Inc.
  • 42. Links to the Same Document โ€“ Example (2) 42 <h1>Table of Contents</h1> <p><a href="#section1">Introduction</a><br /> <a href="#section2">Some background</A><br /> <a href="#section2.1">Project History</a><br /> ...the rest of the table of contents... <!-- The document text follows here --> <h2 id="section1">Introduction</h2> ... Section 1 follows here ... <h2 id="section2">Some background</h2> ... Section 2 follows here ... <h3 id="section2.1">Project History</h3> ... Section 2.1 follows here ... links-to-same-document.html ยฉ Sun Technologies Inc.
  • 43. ๏‚ฎ Inserting an image with <img> tag: ๏‚ฎ Image attributes: ๏‚ฎ Example: Images: <img> tag src Location of image file (relative or absolute) alt Substitute text for display (e.g. in text mode) height Number of pixels of the height width Number of pixels of the width border Size of border, 0 for no border <img src="/img/basd-logo.png"> <img src="./php.png" alt="PHP Logo" /> ยฉ Sun Technologies Inc. 43
  • 44. Miscellaneous Tags โ€ข <hr />: Draws a horizontal rule (line): โ€ข <center></center>: Deprecated! โ€ข <font></font>: 44 <hr size="5" width="70%" /> <center>Hello World!</center> <font size="3" color="blue">Font3</font> <font size="+4" color="blue">Font+4</font> ยฉ Sun Technologies Inc.
  • 45. Miscellaneous Tags โ€“ Example 45 <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> misc.html ยฉ Sun Technologies Inc.
  • 46. a. Apple b. Orange c. Grapefruit Ordered Lists: <ol> Tag โ€ขCreate an Ordered List using <ol></ol>: โ€ขAttribute values for type are 1, A, a, I, or i 46 1. Apple 2. Orange 3. Grapefruit A. Apple B. Orange C. Grapefruit I. Apple II. Orange III. Grapefruit i. Apple ii. Orange iii. Grapefruit <ol type="1"> <li>Apple</li> <li>Orange</li> <li>Grapefruit</li> </ol> ยฉ Sun Technologies Inc.
  • 47. Unordered Lists: <ul> Tag โ€ข Create an Unordered List using <ul></ul>: โ€ข Attribute values for type are: โ€ขdisc, circle or square 47 โ€ข Apple โ€ข Orange โ€ข Pear o Apple o Orange o Pear ๏‚ง Apple ๏‚ง Orange ๏‚ง Pear <ul type="disk"> <li>Apple</li> <li>Orange</li> <li>Grapefruit</li> </ul> ยฉ Sun Technologies Inc.
  • 48. Definition lists: <dl> tag โ€ข Create definition lists using <dl> โ€ข Pairs of text and associated definition; text is in <dt> tag, definition in <dd> tag โ€ข Renders without bullets โ€ข Definition is indented 48 <dl> <dt>HTML</dt> <dd>A markup language โ€ฆ</dd> <dt>CSS</dt> <dd>Language used to โ€ฆ</dd> </dl> ยฉ Sun Technologies Inc.
  • 49. Lists โ€“ Example 49 <ol type="1"> <li>Apple</li> <li>Orange</li> <li>Grapefruit</li> </ol> <ul type="disc"> <li>Apple</li> <li>Orange</li> <li>Grapefruit</li> </ul> <dl> <dt>HTML</dt> <dd>A markup langโ€ฆ</dd> </dl> lists.html ยฉ Sun Technologies Inc.
  • 50. HTML Special Characters ยฃ&pound;British Pound โ‚ฌ&#8364;Euro "&quot;Quotation Mark ยฅ&yen;Japanese Yen โ€”&mdash;Em Dash &nbsp;Non-breaking Space &&amp;Ampersand >&gt;Greater Than <&lt;Less Than โ„ข&trade;Trademark Sign ยฎ&reg;Registered Trademark Sign ยฉ&copy;Copyright Sign SymbolHTML EntitySymbol Name 50 ยฉ Sun Technologies Inc
  • 51. Special Characters โ€“ Example 51 <p>[&gt;&gt;&nbsp;&nbsp;Welcome &nbsp;&nbsp;&lt;&lt;]</p> <p>&#9658;I have following cards: A&#9827;, K&#9830; and 9&#9829;.</p> <p>&#9658;I prefer hard rock &#9835; music &#9835;</p> <p>&copy; 2006 by Svetlin Nakov &amp; his team</p> <p>Telerik Academyโ„ข</p> special-chars.html ยฉ Sun Technologies Inc.
  • 52. Special Chars โ€“ Example (2) 52 <p>[&gt;&gt;&nbsp;&nbsp;Welcome &nbsp;&nbsp;&lt;&lt;]</p> <p>&#9658;I have following cards: A&#9827;, K&#9830; and 9&#9829;.</p> <p>&#9658;I prefer hard rock &#9835; music &#9835;</p> <p>&copy; 2006 by Svetlin Nakov &amp; his team</p> <p>Telerik Academyโ„ข</p> special-chars.html ยฉ Sun Technologies Inc.
  • 53. Using <DIV> and <SPAN> Block and Inline Elements
  • 54. Block and Inline Elements โ€ข Block elements add a line break before and after them โ€ข <div> is a block element โ€ข Other block elements are <table>, <hr>, headings, lists, <p> and etc. โ€ข Inline elements donโ€™t break the text before and after them โ€ข <span> is an inline element โ€ข Most HTML elements are inline, e.g. <a> 54 ยฉ Sun Technologies Inc.
  • 55. The <div> Tag โ€ข <div> creates logical divisions within a page โ€ข Block style element โ€ข Used with CSS โ€ข Example: 55 <div style="font-size:24px; color:red">DIV example</div> <p>This one is <span style="color:red; font- weight:bold">only a test</span>.</p> div-and-span.html ยฉ Sun Technologies Inc.
  • 56. The <span> Tag โ€ข Inline style element โ€ข Useful for modifying a specific portion of text โ€ข Don't create a separate area (paragraph) in the document โ€ข Very useful with CSS 56 <p>This one is <span style="color:red; font- weight:bold">only a test</span>.</p> <p>This one is another <span style="font-size:32px; font- weight:bold">TEST</span>.</p> span.html ยฉ Sun Technologies Inc.
  • 58. HTML Tables โ€ข Tables represent tabular data โ€ข A table consists of one or several rows โ€ข Each row has one or more columns โ€ข Tables comprised of several core tags: <table></table>: begin / end the table <tr></tr>: create a table row <td></td>: create tabular data (cell) โ€ข Tables should not be used for layout. Use CSS floats 58ยฉ Sun Technologies Inc.
  • 59. HTML Tables (2) โ€ข Start and end of a table โ€ข Start and end of a row โ€ข Start and end of a cell in a row 59 <table> ... </table> <tr> ... </tr> <td> ... </td> ยฉ Sun Technologies Inc.
  • 60. Simple HTML Tables โ€“ Example 60 <table cellspacing="0" cellpadding="5"> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture1.ppt">Lecture 1</a></td> </tr> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture2.ppt">Lecture 2</a></td> </tr> <tr> <td><img src="zip.gif"></td> <td><a href="lecture2-demos.zip"> Lecture 2 - Demos</a></td> </tr> </table> ยฉ Sun Technologies Inc.
  • 61. <table cellspacing="0" cellpadding="5"> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture1.ppt">Lecture 1</a></td> </tr> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture2.ppt">Lecture 2</a></td> </tr> <tr> <td><img src="zip.gif"></td> <td><a href="lecture2-demos.zip"> Lecture 2 - Demos</a></td> </tr> </table> Simple HTML Tables โ€“ Example (2) 61ยฉ Sun Technologies Inc.
  • 62. Complete HTML Tables โ€ข Table rows split into three semantic sections: header, body and footer โ€ข <thead> denotes table header and contains <th> elements, instead of <td> elements โ€ข <tbody> denotes collection of table rows that contain the very data โ€ข <tfoot> denotes table footer but comes BEFORE the <tbody> tag โ€ข <colgroup> and <col> define columns (most often used to set column widths) 62ยฉ Sun Technologies Inc.
  • 63. Complete HTML Table: Example 63 <table> <colgroup> <col style="width:100px" /><col /> </colgroup> <thead> <tr><th>Column 1</th><th>Column 2</th></tr> </thead> <tfoot> <tr><td>Footer 1</td><td>Footer 2</td></tr> </tfoot> <tbody> <tr><td>Cell 1.1</td><td>Cell 1.2</td></tr> <tr><td>Cell 2.1</td><td>Cell 2.2</td></tr> </tbody> </table> header footer Last comes the body (data) th columns ยฉ Sun Technologies Inc.
  • 64. <table> <colgroup> <col style="width:200px" /><col /> </colgroup> <thead> <tr><th>Column 1</th><th>Column 2</th></tr> </thead> <tfoot> <tr><td>Footer 1</td><td>Footer 2</td></tr> </tfoot> <tbody> <tr><td>Cell 1.1</td><td>Cell 1.2</td></tr> <tr><td>Cell 2.1</td><td>Cell 2.2</td></tr> </tbody> </table> Complete HTML Table: Example (2) 64 table-full.html Although the footer is before the data in the code, it is displayed last By default, header text is bold and centered. ยฉ Sun Technologies Inc.
  • 65. Nested Tables โ€ขTable data โ€œcellsโ€ (<td>) can contain nested tables (tables within tables): 65 <table> <tr> <td>Contact:</td> <td> <table> <tr> <td>First Name</td> <td>Last Name</td> </tr> </table> </td> </tr> </table> nested-tables.html ยฉ Sun Technologies Inc.
  • 66. ๏‚ฎ cellpadding ๏‚ฎ Defines the empty space around the cell content ๏‚ฎ cellspacing ๏‚ฎ Defines the empty space between cells Cell Spacing and Padding โ€ข Tables have two important attributes: 66 cell cell cell cell cell cell cell cell ยฉ Sun Technologies Inc.
  • 67. Cell Spacing and Padding โ€“ Example 67 <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> table-cells.html ยฉ Sun Technologies Inc.
  • 68. Cell Spacing and Padding โ€“ Example (2) 68 <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> table- cells.html ยฉ Sun Technologies Inc.
  • 69. ๏‚ฎ rowspan ๏‚ฎ Defines how many rows the cell occupies ๏‚ฎ colspan ๏‚ฎ Defines how many columns the cell occupies Column and Row Span โ€ข Table cells have two important attributes: 69 cell[1,1 ] cell[1,2] cell[2,1] colspan=" 1" colspan=" 1" colspan=" 2" cell[1,1] cell[1,2 ] cell[2,1 ] rowspan=" 2" rowspan=" 1" rowspan=" 1" ยฉ Sun Technologies Inc.
  • 70. Column and Row Span โ€“ Example 70 <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> table-colspan-rowspan.html ยฉ Sun Technologies Inc.
  • 71. <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> Column and Row Span โ€“ Example (2) 71 table-colspan-rowspan.html Cell[2,3]Cell[1,3] Cell[3,2] Cell[2,2] Cell[1,2] Cell[2,1]Cell[1,1] ยฉ Sun Technologies Inc.
  • 72. HTML FormsEntering User Data from a Web Page
  • 73. HTML Forms โ€ข Forms are the primary method for gathering data from site visitors โ€ข Create a form block with โ€ข Example: 73 <form></form> <form name="myForm" method="post" action="path/to/some-script.php"> ... </form> The "action" attribute tells where the form data should be sent The โ€œmethod" attribute tells how the form data should be sent โ€“ via GET or POST request ยฉ Sun Technologies Inc.
  • 74. Form Fields โ€ขSingle-line text input fields: โ€ขMulti-line textarea fields: โ€ขHidden fields contain data not shown to the user: โ€ขOften used by JavaScript code 76 <input type="text" name="FirstName" value="This is a text field" /> <textarea name="Comments">This is a multi-line text field</textarea> <input type="hidden" name="Account" value="This is a hidden text field" /> ยฉ Sun Technologies Inc.
  • 75. Fieldsets โ€ขFieldsets are used to enclose a group of related form fields: 75 <form method="post" action="form.aspx"> <fieldset> <legend>Client Details</legend> <input type="text" id="Name" /> <input type="text" id="Phone" /> </fieldset> <fieldset> <legend>Order Details</legend> <input type="text" id="Quantity" /> <textarea cols="40" rows="10" id="Remarks"></textarea> </fieldset> </form> ยฉ Sun Technologies Inc.
  • 76. Form Input Controls โ€ขCheckboxes: โ€ขRadio buttons: โ€ขRadio buttons can be grouped, allowing only one to be selected from a group: 76 <input type="checkbox" name="fruit" value="apple" /> <input type="radio" name="title" value="Mr." /> <input type="radio" name="city" value="Lom" /> <input type="radio" name="city" value="Ruse" /> ยฉ Sun Technologies Inc.
  • 77. Other Form Controls โ€ข Dropdown menus: โ€ข Submit button: 77 <select name="gender"> <option value="Value 1" selected="selected">Male</option> <option value="Value 2">Female</option> <option value="Value 3">Other</option> </select> <input type="submit" name="submitBtn" value="Apply Now" /> ยฉ Sun Technologies Inc.
  • 78. Other Form Controls (2) Reset button โ€“ brings the form to its initial state Image button โ€“ acts like submit but image is displayed and click coordinates are sent Ordinary button โ€“ used for Javascript, no default action 78 <input type="reset" name="resetBtn" value="Reset the form" /> <input type="image" src="submit.gif" name="submitBtn" alt="Submit" /> <input type="button" value="click me" /> ยฉ Sun Technologies Inc.
  • 79. Other Form Controls (3) โ€ขPassword input โ€“ a text field which masks the entered text with * signs โ€ขMultiple select field โ€“ displays the list of items in multiple lines, instead of one 79 <input type="password" name="pass" /> <select name="products" multiple="multiple"> <option value="Value 1" selected="selected">keyboard</option> <option value="Value 2">mouse</option> <option value="Value 3">speakers</option> </select> ยฉ Sun Technologies Inc.
  • 80. Other Form Controls (4) โ€ขFile input โ€“ a field used for uploading files โ€ขWhen used, it requires the form element to have a specific attribute: 80 <input type="file" name="photo" /> <form enctype="multipart/form-data"> ... <input type="file" name="photo" /> ... </form> ยฉ Sun Technologies Inc.
  • 81. Labels โ€ขForm labels are used to associate an explanatory text to a form field using the field's ID. โ€ขClicking on a label focuses its associated field (checkboxes are toggled, radio buttons are checked) โ€ขLabels are both a usability and accessibility feature and are required in order to pass accessibility validation. 81 <label for="fn">First Name</label> <input type="text" id="fn" /> ยฉ Sun Technologies Inc.
  • 82. HTML Forms โ€“ Example 82 <form method="post" action="apply-now.php"> <input name="subject" type="hidden" value="Class" /> <fieldset><legend>Academic information</legend> <label for="degree">Degree</label> <select name="degree" id="degree"> <option value="BA">Bachelor of Art</option> <option value="BS">Bachelor of Science</option> <option value="MBA" selected="selected">Master of Business Administration</option> </select> <br /> <label for="studentid">Student ID</label> <input type="password" name="studentid" /> </fieldset> <fieldset><legend>Personal Details</legend> <label for="fname">First Name</label> <input type="text" name="fname" id="fname" /> <br /> <label for="lname">Last Name</label> <input type="text" name="lname" id="lname" /> form.html ยฉ Sun Technologies Inc.
  • 83. HTML Forms โ€“ Example (2) 83 <br /> Gender: <input name="gender" type="radio" id="gm" value="m" /> <label for="gm">Male</label> <input name="gender" type="radio" id="gf" value="f" /> <label for="gf">Female</label> <br /> <label for="email">Email</label> <input type="text" name="email" id="email" /> </fieldset> <p> <textarea name="terms" cols="30" rows="4" readonly="readonly">TERMS AND CONDITIONS...</textarea> </p> <p> <input type="submit" name="submit" value="Send Form" /> <input type="reset" value="Clear Form" /> </p> </form> form.html (continued) ยฉ Sun Technologies Inc.
  • 84. form.html (continued) HTML Forms โ€“ Example (3) 84ยฉ Sun Technologies Inc.
  • 85. TabIndex โ€ข The TabIndex HTML attribute controls the order in which form fields and hyperlinks are focused when repeatedly pressing the TAB key โ€ข TabIndex="0" (zero) - "natural" order โ€ข If X > Y, then elements with TabIndex="X" are iterated before elements with TabIndex="Y" โ€ข Elements with negative TabIndex are skipped, however, this is not defined in the standard 85 <input type="text" tabindex="10" /> ยฉ Sun Technologies Inc.
  • 87. 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 engines, etc.) โ€ข A <noframes> element is used to provide content for non-compatible agents. 87ยฉ Sun Technologies Inc.
  • 88. HTML Frames โ€“ Demo 88 <html> <head><title>Frames Example</title></head> <frameset cols="180px,*,150px"> <frame src="left.html" /> <frame src="middle.html" /> <frame src="right.html" /> </frameset> </html> frames.html ๏‚ฎ Note the target attribute applied to the <a> elements in the left frame. ยฉ Sun Technologies Inc.
  • 89. Inline Frames: <iframe> โ€ข Inline frames provide a way to show one website inside another website: 89 <iframe name="iframeGoogle" width="600" height="400" src="http://www.google.com" frameborder="yes" scrolling="yes"></iframe> iframe-demo.html ยฉ Sun Technologies Inc.
  • 91. 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 โ€ข Visibility, Display, Overflow โ€ข CSS Development Tools 91ยฉ Sun Technologies Inc.
  • 92. CSS: A New Philosophy โ€ข Separate content from presentation! 92 Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum. โ€ข Vestibulum et odio et ipsum โ€ข accumsan accumsan. Morbi at โ€ข arcu vel elit ultricies porta. Proin tortor purus, luctus non, aliquam nec, interdum vel, mi. Sed nec quam nec odio lacinia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus. Bold Italics Indent Content (HTML document) Presentation (CSS Document) ยฉ Sun Technologies Inc.
  • 93. The Resulting Page 93 Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum. โ€ข Vestibulum et odio et ipsum โ€ข accumsan accumsan. Morbi at โ€ข arcu vel elit ultricies porta. Proin Tortor purus, luctus non, aliquam nec, interdum vel, mi. Sed nec quam nec odio lacinia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus. ยฉ Sun Technologies Inc.
  • 94. CSS Intro Styling with Cascading Stylesheets
  • 95. CSS Introduction โ€ขCascading Style Sheets (CSS) โ€ขUsed to describe the presentation of documents โ€ขDefine sizes, spacing, fonts, colors, layout, etc. โ€ขImprove content accessibility โ€ขImprove flexibility โ€ขDesigned to separate presentation from content โ€ขDue to CSS, all HTML presentation tags and attributes are deprecated, e.g. font, center, etc. 95ยฉ Sun Technologies Inc.
  • 96. CSS Introduction (2) โ€ข CSS can be applied to any XML document โ€ข Not just to HTML / XHTML โ€ข CSS can specify different styles for different media โ€ข On-screen โ€ข In print โ€ข Handheld, projection, etc. โ€ข โ€ฆ even by voice or Braille-based reader 96ยฉ Sun Technologies Inc.
  • 97. Why โ€œCascadingโ€? โ€ข Priority scheme determining which style rules apply to element โ€ข Cascade priorities or specificity (weight) are calculated and assigned to the rules โ€ข Child elements in the HTML DOM tree inherit styles from their parent โ€ข Can override them โ€ข Control via !important rule 97 ยฉ Sun Technologies Inc.
  • 99. Why โ€œCascadingโ€? (3) โ€ข Some CSS styles are inherited and some not โ€ข Text-related and list-related properties are inherited - color, font- size, font-family, line-height, text-align, list- style, etc โ€ข Box-related and positioning styles are not inherited - width, height, border, margin, padding, position, float, etc โ€ข<a> elements do not inherit color and text-decoration 99ยฉ Sun Technologies Inc.
  • 100. Style Sheets Syntax โ€ขStylesheets consist of rules, selectors, declarations, properties and values โ€ขSelectors are separated by commas โ€ขDeclarations are separated by semicolons โ€ขProperties and values are separated by colons 100 h1,h2,h3 { color: green; font-weight: bold; } http://css.maxdesign.com.a u/ ยฉ Sun Technologies Inc.
  • 101. Selectors โ€ข Selectors determine which element the rule applies to: โ€ข All elements of specific type (tag) โ€ข Those that mach a specific attribute (id, class) โ€ข Elements may be matched depending on how they are nested in the document tree (HTML) โ€ข Examples: 101 .header a { color: green } #menu>li { padding-top: 8px } ยฉ Sun Technologies Inc.
  • 102. Selectors (2) โ€ขThree primary kinds of selectors: โ€ข By tag (type selector): โ€ข By element id: โ€ข By element class name (only for HTML): โ€ขSelectors can be combined with commas: This will match <h1> tags, elements with class link, and element with id top-link 102 h1 { font-family: verdana,sans-serif; } #element_id { color: #ff0000; } .myClass {border: 1px solid red} h1, .link, #top-link {font-weight: bold} ยฉ Sun Technologies Inc.
  • 103. Selectors (3) โ€ข Pseudo-classes define state โ€ข :hover, :visited, :active , :lang โ€ข Pseudo-elements define element "parts" or are used to generate content โ€ข :first-line , :before, :after 103 a:hover { color: red; } p:first-line { text-transform: uppercase; } .title:before { content: "ยป"; } .title:after { content: "ยซ"; } ยฉ Sun Technologies Inc.
  • 104. Selectors (4) โ€ขMatch relative to element placement: This will match all <a> tags that are inside of <p> โ€ข* โ€“ universal selector (avoid or use with care!): This will match all descendants of <p> element โ€ข+ selector โ€“ used to match โ€œnext siblingโ€: This will match all siblings with class name link that appear immediately after <img> tag 104 p a {text-decoration: underline} p * {color: black} img + .link {float:right} ยฉ Sun Technologies Inc.
  • 105. Selectors (5) โ€ข> selector โ€“ matches direct child nodes: This will match all elements with class error, direct children of <p> tag โ€ข[ ] โ€“ matches tag attributes by regular expression: This will match all <img> tags with alt attribute containing the word logo โ€ข.class1.class2 (no space) - matches elements with both (all) classes applied at the same time 105 p > .error {font-size: 8px} img[alt~=logo] {border: none} ยฉ Sun Technologies Inc.
  • 106. Values in the CSS Rules โ€ขColors are set in RGB format (decimal or hex): โ€ขExample: #a0a6aa = rgb(160, 166, 170) โ€ขPredefined color aliases exist: black, blue, etc. โ€ขNumeric values are specified in: โ€ขPixels, ems, e.g. 12px , 1.4em โ€ขPoints, inches, centimeters, millimeters โ€ข E.g. 10pt , 1in, 1cm, 1mm โ€ขPercentages, e.g. 50% โ€ข Percentage of what?... โ€ข Zero can be used with no unit: border: 0; 106ยฉ Sun Technologies Inc.
  • 107. Default Browser Styles โ€ข Browsers have default CSS styles โ€ข Used when there is no CSS information or any other style information in the document โ€ข Caution: default styles differ in browsers โ€ข E.g. margins, paddings and font sizes differ most often and usually developers reset them 107 * { margin: 0; padding: 0; } body, h1, p, ul, li { margin: 0; padding: 0; } ยฉ Sun Technologies Inc.
  • 108. Linking HTML and CSS โ€ข HTML (content) and CSS (presentation) can be linked in three ways: โ€ข Inline: the CSS rules in the style attribute โ€ข No selectors are needed โ€ข Embedded: in the <head> in a <style> tag โ€ข External: CSS rules in separate file (best) โ€ข Usually a file with .css extension โ€ข Linked via <link rel="stylesheet" href=โ€ฆ> tag or @import directive in embedded CSS block 108ยฉ Sun Technologies Inc.
  • 109. Linking HTML and CSS (2) โ€ข Using external files is highly recommended โ€ข Simplifies the HTML document โ€ข Improves page load speed as the CSS file is cached 109ยฉ Sun Technologies Inc.
  • 110. Inline Styles: Example 110 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Inline Styles</title> </head> <body> <p>Here is some text</p> <!--Separate multiple styles with a semicolon--> <p style="font-size: 20pt">Here is some more text</p> <p style="font-size: 20pt;color: #0000FF" >Even more text</p> </body> </html> inline-styles.html ยฉ Sun Technologies Inc.
  • 111. Inline Styles: Example 111 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Inline Styles</title> </head> <body> <p>Here is some text</p> <!--Separate multiple styles with a semicolon--> <p style="font-size: 20pt">Here is some more text</p> <p style="font-size: 20pt;color: #0000FF" >Even more text</p> </body> </html> inline-styles.html ยฉ Sun Technologies Inc.
  • 112. CSS Cascade (Precedence) โ€ข There are browser, user and author stylesheets with "normal" and "important" declarations โ€ข Browser styles (least priority) โ€ข Normal user styles โ€ข Normal author styles (external, in head, inline) โ€ข Important author styles โ€ข Important user styles (max priority) 112 a { color: red !important ; } http://www.slideshare.net/maxdesign/css-cascade- 1658158 ยฉ Sun Technologies Inc.
  • 113. CSS Specificity โ€ข CSS specificity is used to determine the precedence of CSS style declarations with the same origin. Selectors are what matters โ€ข Simple calculation: #id = 100, .class = 10, :pseudo = 10, [attr] = 10, tag = 1, * = 0 โ€ข Same number of points? Order matters. โ€ข See also: โ€ข http://www.smashingmagazine.com/2007/07/27/css-specificity- things-you-should-know/ โ€ข http://css.maxdesign.com.au/selectutorial/advanced_conflict.ht m 113ยฉ Sun Technologies Inc.
  • 114. Embedded Styles โ€ข Embedded in the HTML in the <style> tag: โ€ข The <style> tag is placed in the <head> section of the document โ€ข type attribute specifies the MIME type โ€ข MIME describes the format of the content โ€ข Other MIME types include text/html, image/gif, text/javascript โ€ฆ โ€ข Used for document-specific styles 114 <style type="text/css"> ยฉ Sun Technologies Inc.
  • 115. Embedded Styles: Example 115 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.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> embedded-stylesheets.html ยฉ Sun Technologies Inc.
  • 116. Embedded Styles: Example (2) 116 โ€ฆ <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> ยฉ Sun Technologies Inc.
  • 117. โ€ฆ <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> Embedded Styles: Example (3) 117ยฉ Sun Technologies Inc.
  • 118. External CSS Styles โ€ข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/) โ€ขlink tag (with a rel attribute) โ€ขSpecifies a relationship between current document and another document โ€ข link elements should be in the <head> 118 <link rel="stylesheet" type="text/css" href="styles.css"> ยฉ Sun Technologies Inc.
  • 119. External CSS Styles (2) @import โ€ข Another way to link external CSS files โ€ข Example: โ€ข Ancient browsers do not recognize @import โ€ข Use @import in an external CSS file to workaround the IE 32 CSS file limit 119 <style type="text/css"> @import url("styles.css"); /* same as */ @import "styles.css"; </style> ยฉ Sun Technologies Inc.
  • 120. External Styles: Example 120 /* CSS Document */ a { text-decoration: none } a:hover { text-decoration: underline; color: red; background-color: #CCFFCC } li em { color: red; font-weight: bold } ul { margin-left: 2cm } ul ul { text-decoration: underline; margin-left: .5cm } styles.css ยฉ Sun Technologies Inc.
  • 121. External Styles: Example (2) 121 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Importing style sheets</title> <link type="text/css" rel="stylesheet" href="styles.css" /> </head> <body> <h1>Shopping list for <em>Monday</em>:</h1> <li>Milk</li> โ€ฆ external-styles.html ยฉ Sun Technologies Inc.
  • 122. External Styles: Example (3) 122 โ€ฆ <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> ยฉ Sun Technologies Inc.
  • 123. โ€ฆ <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> External Styles: Example (4) 123ยฉ Sun Technologies Inc.
  • 124. Text-related CSS Properties โ€ขcolor โ€“ specifies the color of the text โ€ขfont-size โ€“ size of font: xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger or numeric value โ€ขfont-family โ€“ comma separated font names โ€ขExample: verdana, sans-serif, etc. โ€ขThe browser loads the first one that is available โ€ขThere should always be at least one generic font โ€ขfont-weight can be normal, bold, bolder, lighter or a number in range [100 โ€ฆ 900] 124 ยฉ Sun Technologies Inc.
  • 125. CSS Rules for Fonts (2) โ€ข font-style โ€“ styles the font โ€ข Values: normal, italic, oblique โ€ข text-decoration โ€“ decorates the text โ€ข Values: none, underline, line-trough, overline, blink โ€ข text-align โ€“ defines the alignment of text or other content โ€ข Values: left, right, center, justify 125ยฉ Sun Technologies Inc.
  • 126. Shorthand Font Property โ€ข font โ€ข Shorthand rule for setting multiple font properties at the same time is equal to writing this: 126 font:italic normal bold 12px/16px verdana font-style: italic; font-variant: normal; font-weight: bold; font-size: 12px; line-height: 16px; font-family: verdana; ยฉ Sun Technologies Inc.
  • 127. Backgrounds โ€ข background-image โ€ข URL of image to be used as background, e.g.: โ€ข background-color โ€ข Using color and image and the same time โ€ข background-repeat โ€ข repeat-x, repeat-y, repeat, no-repeat โ€ข background-attachment โ€ข fixed / scroll 127 background-image:url("back.gif"); ยฉ Sun Technologies Inc.
  • 128. 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: 128 background-position: top left; background-position: -5px 50%; ยฉ Sun Technologies Inc.
  • 129. Background Shorthand Property โ€ขbackground: shorthand rule for setting background properties at the same time: is equal to writing: โ€ขSome browsers will not apply BOTH color and image for background if using shorthand rule 129 background: #FFF0C0 url("back.gif") no-repeat fixed top; background-color: #FFF0C0; background-image: url("back.gif"); background-repeat: no-repeat; background-attachment: fixed; background-position: top; ยฉ Sun Technologies Inc.
  • 130. Background-image or <img>? โ€ข Background images allow you to save many image tags from the HTML โ€ข Leads to less code โ€ข More content-oriented approach โ€ข All images that are not part of the page content (and are used only for "beautification") should be moved to the CSS 130ยฉ Sun Technologies Inc.
  • 131. 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-color, โ€ฆ 131ยฉ Sun Technologies Inc.
  • 132. Border Shorthand Property โ€ข border: shorthand rule for setting border properties at once: is equal to writing: โ€ข Specify different borders for the sides via shorthand rules: border-top, border-left, border-right, border-bottom โ€ข When to avoid border:0 132 border: 1px solid red border-width:1px; border-color:red; border-style:solid; ยฉ Sun Technologies Inc.
  • 133. Width and Height โ€ข width โ€“ defines numerical value for the width of element, e.g. 200px โ€ข height โ€“ defines numerical value for the height of element, e.g. 100px โ€ข By default the height of an element is defined by its content โ€ข Inline elements do not apply height, unless you change their display style. 133ยฉ Sun Technologies Inc.
  • 134. Margin and Padding โ€ข margin and padding define the spacing around the element โ€ข Numerical value, e.g. 10px or -5px โ€ข Can be defined for each of the four sides separately - margin-top, padding-left, โ€ฆ โ€ข margin is the spacing outside of the border โ€ข padding is the spacing between the border and the content โ€ข What are collapsing margins? 134ยฉ Sun Technologies Inc.
  • 135. Margin and Padding: Short Rules โ€ข margin: 5px; โ€ข Sets all four sides to have margin of 5 px; โ€ข margin: 10px 20px; โ€ข top and bottom to 10px, left and right to 20px; โ€ข margin: 5px 3px 8px; โ€ข top 5px, left/right 3px, bottom 8px โ€ข margin: 1px 3px 5px 7px; โ€ข top, right, bottom, left (clockwise from top) โ€ข Same for padding 135ยฉ Sun Technologies Inc.
  • 136. The Box Model 136ยฉ Sun Technologies Inc.
  • 137. 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 137ยฉ Sun Technologies Inc.
  • 138. 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 138ยฉ Sun Technologies Inc.
  • 139. 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 โ€ข Their position and size is ignored when calculating the size of parent element or position of surrounding elements โ€ข Overlaid according to their z-index โ€ข Inline fixed or absolutely positioned elements can apply height like block-level elements 139ยฉ Sun Technologies Inc.
  • 140. 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 โ€ข Understanding stacking context 140 Each positioned element creates a stacking context. Elements in different stacking contexts are overlapped according to the stacking order of their containers. For example, there is no way for #A1 and #A2 (children of #A) to be placed over #B without increasing the z- index of #A. ยฉ Sun Technologies Inc.
  • 141. Inline element positioning โ€ข vertical-align: sets the vertical-alignment of an inline element, according to the line height โ€ข Values: baseline, sub, super, top, text-top, middle, bottom, text-bottom or numeric ๏‚ฎ Also used for content of table cells (which apply middle alignment by default) 141ยฉ Sun Technologies Inc.
  • 142. Float โ€ข float: the element โ€œfloatsโ€ to one side โ€ข left: places the element on the left and following content on the right โ€ข right: places the element on the right and following content on the left โ€ข floated elements should come before the content that will wrap around them in the code โ€ข margins of floated elements do not collapse โ€ข floated inline elements can apply height 142ยฉ Sun Technologies Inc.
  • 143. Float (2) โ€ข How floated elements are positioned 143ยฉ Sun Technologies Inc.
  • 144. Clear โ€ข clear โ€ข Sets the sides of the element where other floating elements are NOT allowed โ€ข Used to "drop" elements below floated ones or expand a container, which contains only floated children โ€ข Possible values: left, right, both โ€ขClearing floats โ€ข additional element (<div>) with a clear style 144ยฉ Sun Technologies Inc.
  • 145. Clear (2) โ€ขClearing floats (continued) โ€ข :after { content: ""; display: block; clear: both; height: 0; } โ€ข Triggering hasLayout in IE expands a container of floated elements โ€ข display: inline-block; โ€ข zoom: 1; 145ยฉ Sun Technologies Inc.
  • 146. Opacity โ€ข opacity: specifies the opacity of the element โ€ข Floating point number from 0 to 1 โ€ข For old Mozilla browsers use โ€“moz-opacity โ€ข For IE use filter:alpha(opacity=value) where value is from 0 to 100; also, "binary and script behaviors" must be enabled and hasLayout must be triggered, e.g. with zoom:1 146ยฉ Sun Technologies Inc.
  • 147. 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 147ยฉ Sun Technologies Inc.
  • 148. Display โ€ข display: controls the display of the element and the way it is rendered and if breaks should be placed before and after the element โ€ข inline: no breaks are placed before and after (<span> is an inline element) โ€ข block: breaks are placed before AND after the element (<div> is a block element) 148ยฉ Sun Technologies Inc.
  • 149. Display (2) โ€ข display: controls the display of the element and the way it is rendered and if breaks should be placed before and after the element โ€ข none: element is hidden and its dimensions are not used to calculate the surrounding elements rendering (differs from visibility: hidden!) โ€ข There are some more possible values, but not all browsers support them โ€ข Specific displays like table-cell and table-row 149ยฉ Sun Technologies Inc.
  • 150. Overflow โ€ขoverflow: defines the behavior of element when content needs more space than you have specified by the size properties or for other reasons. Values: โ€ขvisible (default) โ€“ content spills out of the element โ€ขauto - show scrollbars if needed โ€ขscroll โ€“ always show scrollbars โ€ขhidden โ€“ any content that cannot fit is clipped 150 ยฉ Sun Technologies Inc.
  • 151. Other CSS Properties โ€ข cursor: specifies the look of the mouse cursor when placed over the element โ€ข Values: crosshair, help, pointer, progress, move, hair, col-resize, row- resize, text, wait, copy, drop, and others โ€ข white-space โ€“ controls the line breaking of text. Value is one of: โ€ข nowrap โ€“ keeps the text on one line 1. normal (default) โ€“ browser decides whether to brake the lines if needed โ€ข 15111ยฉ Sun Technologies Inc.
  • 152. Benefits of using CSS โ€ข More powerful formatting than using presentation tags โ€ข Your pages load faster, because browsers cache the .css files โ€ข Increased accessibility, because rules can be defined according given media โ€ข Pages are easier to maintain and update 152ยฉ Sun Technologies Inc.
  • 153. Maintenance Example 153 Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css.Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. Title Some random text here. You canโ€™t read it anyway! Har har har! Use Css. CSS file ยฉ Sun Technologies Inc.
  • 154. CSS Development Tools โ€ข Visual Studio โ€“ CSS Editor 154ยฉ Sun Technologies Inc.
  • 155. CSS Development Tools (3) โ€ข Firebug โ€“ add-on to Firefox used to examine and adjust CSS and HTML 155ยฉ Sun Technologies Inc.
  • 156. CSS Development Tools (4) โ€ข IE Developer Toolbar โ€“ add-on to IE used to examine CSS and HTML (press [F12]) 156ยฉ Sun Technologies Inc.
  • 158. Table of Contents โ€ข What is DHTML? โ€ข DHTML Technologies โ€ข XHTML, CSS, JavaScript, DOM 158ยฉ Sun Technologies Inc.
  • 159. Table of Contents (2) โ€ข Introduction to JavaScript โ€ข What is JavaScript โ€ข Implementing JavaScript into Web pages โ€ข In <head> part โ€ข In <body> part โ€ข In external .js file 159 ยฉ Sun Technologies Inc.
  • 160. Table of Contents (3) โ€ข JavaScript Syntax โ€ข JavaScript operators โ€ข JavaScript Data Types โ€ข JavaScript Pop-up boxes โ€ข alert, confirm and prompt โ€ข Conditional and switch statements, loops and functions โ€ข Document Object Model โ€ข Debugging in JavaScript 160ยฉ Sun Technologies Inc.
  • 161. DHTML Dynamic Behavior at the Client Side
  • 162. What is DHTML? โ€ข Dynamic HTML (DHTML) โ€ข Makes possible a Web page to react and change in response to the userโ€™s actions โ€ข DHTML = HTML + CSS + JavaScript 162 DHTML XHTML CSS JavaScript DOM ยฉ Sun Technologies Inc.
  • 163. DTHML = HTML + CSS + JavaScript โ€ข HTML defines Web sites content through semantic tags (headings, paragraphs, lists, โ€ฆ) โ€ข CSS defines 'rules' or 'styles' for presenting every aspect of an HTML document โ€ข Font (family, size, color, weight, etc.) โ€ข Background (color, image, position, repeat) โ€ข Position and layout (of any object on the page) โ€ข JavaScript defines dynamic behavior โ€ข Programming logic for interaction with the user, to handle events, etc. 163ยฉ Sun Technologies Inc.
  • 165. JavaScript โ€ข JavaScript is a front-end scripting language developed by Netscape for dynamic content โ€ข Lightweight, but with limited capabilities โ€ข Can be used as object-oriented language โ€ข Client-side technology โ€ข Embedded in your HTML page โ€ข Interpreted by the Web browser โ€ข Simple and flexible โ€ข Powerful to manipulate the DOM 165ยฉ Sun Technologies Inc.
  • 166. JavaScript Advantages โ€ข JavaScript allows interactivity such as: โ€ข Implementing form validation โ€ข React to user actions, e.g. handle keys โ€ข Changing an image on moving mouse over it โ€ข Sections of a page appearing and disappearing โ€ข Content loading and changing dynamically โ€ข Performing complex calculations โ€ข Custom HTML controls, e.g. scrollable table โ€ข Implementing AJAX functionality 166ยฉ Sun Technologies Inc.
  • 167. What Can JavaScript Do? โ€ข Can handle events โ€ข Can read and write HTML elements and modify the DOM tree โ€ข Can validate form data โ€ข Can access / modify browser cookies โ€ข Can detect the userโ€™s browser and OS โ€ข Can be used as object-oriented language โ€ข Can handle exceptions โ€ข Can perform asynchronous server calls (AJAX) 167 ยฉ Sun Technologies Inc.
  • 168. The First Script first-script.html 168 <html> <body> <script type="text/javascript"> alert('Hello JavaScript!'); </script> </body> </html> ยฉ Sun Technologies Inc.
  • 169. Another Small Example small-example.html 169 <html> <body> <script type="text/javascript"> document.write('JavaScript rulez!'); </script> </body> </html> ยฉ Sun Technologies Inc.
  • 170. Using JavaScript Code โ€ข The JavaScript code can be placed in: โ€ข <script> tag in the head โ€ข <script> tag in the body โ€“ not recommended โ€ข External files, linked via <script> tag the head โ€ข Files usually have .js extension โ€ข Highly recommended โ€ข The .js files get cached by the browser 170 <script src="scripts.js" type="text/javscript"> <!โ€“ code placed here will not be executed! --> </script> ยฉ Sun Technologies Inc.
  • 171. JavaScript โ€“ When is Executed? โ€ข JavaScript code is executed during the page loading or when the browser fires an event โ€ข All statements are executed at page loading โ€ข Some statements just define functions that can be called later โ€ข Function calls or code can be attached as "event handlers" via tag attributes โ€ข Executed when the event is fired by the browser 171 <img src="logo.gif" onclick="alert('clicked!')" /> ยฉ Sun Technologies Inc.
  • 172. <html> <head> <script type="text/javascript"> function test (message) { alert(message); } </script> </head> <body> <img src="logo.gif" onclick="test('clicked!')" /> </body> </html> Calling a JavaScript Function from Event Handler โ€“ Example image-onclick.html 172ยฉ Sun Technologies Inc.
  • 173. Using External Script Files โ€ขUsing external script files: โ€ขExternal JavaScript file: 173 <html> <head> <script src="sample.js" type="text/javascript"> </script> </head> <body> <button onclick="sample()" value="Call JavaScript function from sample.js" /> </body> </html> function sample() { alert('Hello from sample.js!') } external- JavaScript.html sample.js The <script> tag is always empty. ยฉ Sun Technologies Inc.
  • 175. JavaScript Syntax โ€ข The JavaScript syntax is similar to C# and Java โ€ข Operators (+, *, =, !=, &&, ++, โ€ฆ) โ€ข Variables (typeless) โ€ข Conditional statements (if, else) โ€ข Loops (for, while) โ€ข Arrays (my_array[]) and associative arrays (my_array['abc']) โ€ข Functions (can return value) โ€ข Function variables (like the C# delegates) 175ยฉ Sun Technologies Inc.
  • 176. Data Types โ€ข JavaScript data types: โ€ข Numbers (integer, floating-point) โ€ข Boolean (true / false) โ€ข String type โ€“ string of characters โ€ข Arrays โ€ข Associative arrays (hash tables) 176 var myName = "You can use both single or double quotes for strings"; var my_array = [1, 5.3, "aaa"]; var my_hash = {a:2, b:3, c:"text"}; ยฉ Sun Technologies Inc.
  • 177. Everything is Object โ€ข Every variable can be considered as object โ€ข For example strings and arrays have member functions: 177 var test = "some string"; alert(test[7]); // shows letter 'r' alert(test.charAt(5)); // shows letter 's' alert("test".charAt(1)); //shows letter 'e' alert("test".substring(1,3)); //shows 'es' var arr = [1,3,4]; alert (arr.length); // shows 3 arr.push(7); // appends 7 to end of array alert (arr[3]); // shows 7 objects.html ยฉ Sun Technologies Inc.
  • 178. String Operations โ€ข The + operator joins strings โ€ข What is "9" + 9? โ€ข Converting string to number: 178 string1 = "fat "; string2 = "cats"; alert(string1 + string2); // fat cats alert("9" + 9); // 99 alert(parseInt("9") + 9); // 18 ยฉ Sun Technologies Inc.
  • 179. Arrays Operations and Properties โ€ขDeclaring new empty array: โ€ขDeclaring an array holding few elements: โ€ขAppending an element / getting the last element: โ€ขReading the number of elements (array length): โ€ขFinding element's index in the array: 179 var arr = new Array(); var arr = [1, 2, 3, 4, 5]; arr.push(3); var element = arr.pop(); arr.length; arr.indexOf(1); ยฉ Sun Technologies Inc.
  • 180. Standard Popup Boxes โ€ข Alert box with text and [OK] button โ€ข Just a message shown in a dialog box: โ€ข Confirmation box โ€ข Contains text, [OK] button and [Cancel] button: โ€ข Prompt box โ€ข Contains text, input field with default value: 180 alert("Some text here"); confirm("Are you sure?"); prompt ("enter amount", 10); ยฉ Sun Technologies Inc.
  • 181. Sum of Numbers โ€“ Example sum-of-numbers.html 181 <html> <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> ยฉ Sun Technologies Inc.
  • 182. Sum of Numbers โ€“ Example (2) sum-of-numbers.html (cont.) 182 <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> ยฉ Sun Technologies Inc.
  • 183. JavaScript Prompt โ€“ Example prompt.html 183 price = prompt("Enter the price", "10.00"); alert('Price + VAT = ' + price * 1.2); ยฉ Sun Technologies Inc.
  • 184. Greater than <= Symbo l Meaning > < Less than >= Greater than or equal to Less than or equal to == Equal != Not equal Conditional Statement (if) 184 unitPrice = 1.30; if (quantity > 100) { unitPrice = 1.20; } ยฉ Sun Technologies Inc.
  • 185. Conditional Statement (if) (2) โ€ขThe condition may be of Boolean or integer type: 185 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 + ";"); } conditional-statements.html ยฉ Sun Technologies Inc.
  • 186. Switch Statement โ€ข The switch statement works like in C#: 186 switch (variable) { case 1: // do something break; case 'a': // do something else break; case 3.14: // another code break; default: // something completely different } switch-statements.html ยฉ Sun Technologies Inc.
  • 187. Loops โ€ข Like in C# โ€ข for loop โ€ข while loop โ€ข do โ€ฆ while loop 187 var counter; for (counter=0; counter<4; counter++) { alert(counter); } while (counter < 5) { alert(++counter); } loops.html ยฉ Sun Technologies Inc.
  • 188. Functions โ€ข Code structure โ€“ splitting code into parts โ€ข Data comes in, processed, result returned 188 function average(a, b, c) { var total; total = a+b+c; return total/3; } Parameters come in here. Declaring variables is optional. Type is never declared. Value returned here. ยฉ Sun Technologies Inc.
  • 189. Function Arguments and Return Value โ€ข Functions are not required to return a value โ€ข When calling function it is not obligatory to specify all of its arguments โ€ขThe function has access to all the arguments passed via arguments array 189 function sum() { var sum = 0; for (var i = 0; i < arguments.length; i ++) sum += parseInt(arguments[i]); return sum; } alert(sum(1, 2, 4)); functions-demo.html ยฉ Sun Technologies Inc.
  • 191. Document Object Model (DOM) โ€ขEvery HTML element is accessible via the JavaScript DOM API โ€ขMost DOM objects can be manipulated by the programmer โ€ขThe event model lets a document to react when the user does something on the page โ€ขAdvantages โ€ขCreate interactive pages โ€ขUpdates the objects of a page without reloading it 191ยฉ Sun Technologies Inc.
  • 192. Accessing Elements โ€ข Access elements via their ID attribute โ€ข Via the name attribute โ€ข Via tag name โ€ข Returns array of descendant <img> elements of the element "el" 192 var elem = document.getElementById("some_id") var arr = document.getElementsByName("some_name") var imgTags = el.getElementsByTagName("img") ยฉ Sun Technologies Inc.
  • 193. DOM Manipulation โ€ข Once we access an element, we can read and write its attributes 193 function change(state) { var lampImg = document.getElementById("lamp"); lampImg.src = "lamp_" + state + ".png"; var statusDiv = document.getElementById("statusDiv"); statusDiv.innerHTML = "The lamp is " + state"; } โ€ฆ <img src="test_on.gif" onmouseover="change('off')" onmouseout="change('on')" /> DOM-manipulation.html ยฉ Sun Technologies Inc.
  • 194. Common Element Properties โ€ข Most of the properties are derived from the HTML attributes of the tag โ€ข E.g. id, name, href, alt, title, src, etcโ€ฆ โ€ข style property โ€“ allows modifying the CSS styles of the element โ€ข Corresponds to the inline style of the element โ€ข Not the properties derived from embedded or external CSS rules โ€ข Example: style.width, style.marginTop, style.backgroundImage 194ยฉ Sun Technologies Inc.
  • 195. Common Element Properties (2) โ€ข className โ€“ the class attribute of the tag โ€ข innerHTML โ€“ holds all the entire HTML code inside the element โ€ข Read-only properties with information for the current element and its state โ€ข tagName, offsetWidth, offsetHeight, scrollHeight, scrollTop, nodeType, etcโ€ฆ 195ยฉ Sun Technologies Inc.
  • 196. Accessing Elements through the DOM Tree Structure โ€ข We can access elements in the DOM through some tree manipulation properties: โ€ข element.childNodes โ€ข element.parentNode โ€ข element.nextSibling โ€ข element.previousSibling โ€ข element.firstChild โ€ข element.lastChild 196ยฉ Sun Technologies Inc.
  • 197. Accessing Elements through the DOM Tree โ€“ Example ๏‚ฎ Warning: may not return what you expected due to Browser differences 197 var el = document.getElementById('div_tag'); alert (el.childNodes[0].value); alert (el.childNodes[1]. getElementsByTagName('span').id); โ€ฆ <div id="div_tag"> <input type="text" value="test text" /> <div> <span id="test">test span</span> </div> </div> accessing-elements-demo.html ยฉ Sun Technologies Inc.
  • 199. The HTML DOM Event Model โ€ข JavaScript can register event handlers โ€ข Events are fired by the Browser and are sent to the specified JavaScript event handler function โ€ข Can be set with HTML attributes: โ€ข Can be accessed through the DOM: 199 <img src="test.gif" onclick="imageClicked()" /> var img = document.getElementById("myImage"); img.onclick = imageClicked; ยฉ Sun Technologies Inc.
  • 200. The HTML DOM Event Model (2) โ€ข All event handlers receive one parameter โ€ข It brings information about the event โ€ข Contains the type of the event (mouse click, key press, etc.) โ€ข Data about the location where the event has been fired (e.g. mouse coordinates) โ€ข Holds a reference to the event sender โ€ข E.g. the button that was clicked 200ยฉ Sun Technologies Inc.
  • 201. The HTML DOM Event Model (3) โ€ข Holds information about the state of [Alt], [Ctrl] and [Shift] keys โ€ข Some browsers do not send this object, but place it in the document.event โ€ข Some of the names of the eventโ€™s object properties are browser- specific 201 ยฉ Sun Technologies Inc.
  • 202. Common DOM Events โ€ข Mouse events: โ€ข onclick, onmousedown, onmouseup โ€ข onmouseover, onmouseout, onmousemove โ€ข Key events: โ€ข onkeypress, onkeydown, onkeyup โ€ข Only for input fields โ€ข Interface events: โ€ข onblur, onfocus โ€ข onscroll ยฉ Sun Technologies Inc.
  • 203. Common DOM Events (2) โ€ข Form events โ€ข onchange โ€“ for input fields โ€ข onsubmit โ€ข Allows you to cancel a form submission โ€ข Useful for form validation โ€ข Miscellaneous events โ€ข onload, onunload โ€ข Allowed only for the <body> element โ€ข Fires when all content on the page was loaded / unloaded 203ยฉ Sun Technologies Inc.
  • 204. onload Event โ€“ Example โ€ข onload event 204 <html> <head> <script type="text/javascript"> function greet() { alert("Loaded."); } </script> </head> <body onload="greet()" > </body> </html> onload.html ยฉ Sun Technologies Inc.
  • 206. Built-in Browser Objects โ€ข The browser provides some read-only data via: โ€ข window โ€ข The top node of the DOM tree โ€ข Represents the browser's window โ€ข document โ€ข holds information the current loaded document โ€ข screen โ€ข Holds the userโ€™s display properties โ€ข browser โ€ข Holds information about the browser 206ยฉ Sun Technologies Inc.
  • 207. DOM Hierarchy โ€“ Example 207 window navigator screen document history location form button form form ยฉ Sun Technologies Inc.
  • 208. Opening New Window โ€“ Example โ€ข window.open() 208 var newWindow = window.open("", "sampleWindow", "width=300, height=100, menubar=yes, status=yes, resizable=yes"); newWindow.document.write( "<html><head><title> Sample Title</title> </head><body><h1>Sample Text</h1></body>"); newWindow.status = "Hello folks"; window-open.html ยฉ Sun Technologies Inc.
  • 209. The Navigator Object 209 alert(window.navigator.userAgent); The navigator in the browser window The userAgent (browser ID) The browser window ยฉ Sun Technologies Inc.
  • 210. The Screen Object โ€ข The screen object contains information about the display 210 window.moveTo(0, 0); x = screen.availWidth; y = screen.availHeight; window.resizeTo(x, y); ยฉ Sun Technologies Inc.
  • 211. Document and Location โ€ข document object โ€ข Provides some built-in arrays of specific objects on the currently loaded Web page โ€ข document.location โ€ข Used to access the currently open URL or redirect the browser 211 document.links[0].href = "yahoo.com"; document.write( "This is some <b>bold text</b>"); document.location = "http://www.yahoo.com/"; ยฉ Sun Technologies Inc.
  • 212. Form Validation โ€“ Example 212 function checkForm() { var valid = true; if (document.mainForm.firstName.value == "") { alert("Please type in your first name!"); document.getElementById("firstNameError"). style.display = "inline"; valid = false; } return valid; } โ€ฆ <form name="mainForm" onsubmit="return checkForm()"> <input type="text" name="firstName" /> โ€ฆ </form> form-validation.html ยฉ Sun Technologies Inc.
  • 213. The Math Object โ€ข The Math object provides some mathematical functions 213 for (i=1; i<=20; i++) { var x = Math.random(); x = 10*x + 1; x = Math.floor(x); document.write( "Random number (" + i + ") in range " + "1..10 --> " + x + "<br/>"); } math.html ยฉ Sun Technologies Inc.
  • 214. The Date Object โ€ข The Date object provides date / calendar functions 214 var now = new Date(); var result = "It is now " + now; document.getElementById("timeField") .innerText = result; ... <p id="timeField"></p> dates.html ยฉ Sun Technologies Inc.
  • 215. Timers: setTimeout() โ€ข Make something happen (once) after a fixed delay 215 var timer = setTimeout('bang()', 5000); clearTimeout(timer); 5 seconds after this statement executes, this function is called Cancels the timer ยฉ Sun Technologies Inc.
  • 216. Timers: setInterval() โ€ข Make something happen repeatedly at fixed intervals 216 var timer = setInterval('clock()', 1000); clearInterval(timer); This function is called continuously per 1 second. Stop the timer. ยฉ Sun Technologies Inc.
  • 217. Timer โ€“ Example 217 <script type="text/javascript"> function timerFunc() { var now = new Date(); var hour = now.getHours(); var min = now.getMinutes(); var sec = now.getSeconds(); document.getElementById("clock").value = "" + hour + ":" + min + ":" + sec; } setInterval('timerFunc()', 1000); </script> <input type="text" id="clock" /> timer-demo.html ยฉ Sun Technologies Inc.
  • 219. Debugging JavaScript โ€ข Modern browsers have JavaScript console where errors in scripts are reported โ€ข Errors may differ across browsers โ€ข Several tools to debug JavaScript โ€ข Microsoft Script Editor โ€ข Add-on for Internet Explorer โ€ข Supports breakpoints, watches โ€ข JavaScript statement debugger; opens the script editor 219ยฉ Sun Technologies Inc.
  • 220. Firebug โ€ข Firebug โ€“ Firefox add-on for debugging JavaScript, CSS, HTML โ€ข Supports breakpoints, watches, JavaScript console editor โ€ข Very useful for CSS and HTML too โ€ข You can edit all the document real-time: CSS, HTML, etc โ€ข Shows how CSS rules apply to element โ€ข Shows Ajax requests and responses โ€ข Firebug is written mostly in JavaScript 220ยฉ Sun Technologies Inc.
  • 221. Firebug (2) 221ยฉ Sun Technologies Inc.
  • 222. JavaScript Console Object โ€ข The console object exists only if there is a debugging tool that supports it โ€ข Used to write log messages at runtime โ€ข Methods of the console object: โ€ข debug(message) โ€ข info(message) โ€ข log(message) โ€ข warn(message) โ€ข error(message) 222ยฉ Sun Technologies Inc.
  • 223. HTML, CSS and JavaScript Basics Questions? ยฉ Sun Technologies Inc. 223

Editor's Notes