ak html

99
HTML Atul Kahate [email protected]

Upload: gauravashq

Post on 01-Sep-2014

790 views

Category:

Education


1 download

DESCRIPTION

HTML session by Kahate sir at SICSR

TRANSCRIPT

Page 1: AK  html

HTML

Atul Kahate

[email protected]

Page 2: AK  html

HTML | Atul Kahate 2

HTML History Physicists at CERN (Centre Europeen

pour la Recherche Nucleaire) needed a way to easily share information

In 1980, Tim Berners-Lee developed the initial program for linking documents with each other

A decade of development led to WWW and HTML, including Web browsers

Page 3: AK  html

HTML | Atul Kahate 3

HTML Basics HTML stands for Hyper Text Markup

Language An HTML file is a text file containing

small markup tags The markup tags tell the Web browser

how to display the page An HTML file must have an htm or html

file extension An HTML file can be created using a

simple text editor

Page 4: AK  html

HTML Syntaxes

Page 5: AK  html

HTML | Atul Kahate 5

Sample HTML Page<html><head><title>Title of page</title></head><body>This is my first homepage. <b>This text is bold</b></body></html>

Page 6: AK  html

HTML | Atul Kahate 6

How to view it? Save it with a .htm or .html

extension Open it in browser or by simply

double clicking on it

Page 7: AK  html

HTML | Atul Kahate 7

HTML Tags HTML tags are used to mark-up HTML elements HTML tags are surrounded by the two

characters < and > HTML tags normally come in pairs like <b> and

</b> The first tag in a pair is the start tag, the

second tag is the end tag The text between the start and end tags is the

element content HTML tags are not case sensitive, <b> means

the same as <B>

Page 8: AK  html

HTML | Atul Kahate 8

Why lowercase tags? The World Wide Web Consortium

(W3C) recommends lowercase tags in their HTML 4 recommendation

XHTML (the next generation HTML) demands lowercase tags

Page 9: AK  html

HTML | Atul Kahate 9

Tag Attributes Attributes provide additional information

regarding HTML tags/elements Always added to the start tag Come in name=“value” pairs Examples

<body bgcolor="red"> bgcolor attribute provides additional information

about the body tag (that the background color should be red)

<table border="0"> border attribute states that this table should not

have a border

Page 10: AK  html

HTML | Atul Kahate 10

Headings Headings are defined with the

<h1> to <h6> tags <h1> defines the largest heading <h6> defines the smallest heading HTML automatically adds an extra

blank line before and after a heading

Page 11: AK  html

HTML | Atul Kahate 11

Headings Example<h1>This is a heading</h1><h2>This is a heading</h2><h3>This is a heading</h3><h4>This is a heading</h4><h5>This is a heading</h5><h6>This is a heading</h6>

Page 12: AK  html

HTML | Atul Kahate 12

Aligning Headings Use “align=left/center/right”

attribute Example

<H1 align=“center”>Heading in the center</H1>

Page 13: AK  html

HTML | Atul Kahate 13

Paragraphs Paragraphs are defined with the

<p> tag HTML automatically adds an extra

blank line before and after a paragraph

Page 14: AK  html

HTML | Atul Kahate 14

Paragraphs Example<p>This is a paragraph</p><p>This is another paragraph</p>

Page 15: AK  html

HTML | Atul Kahate 15

Line Breaks <br> tag is used when you want to

end a line Does not start a new paragraph The <br> tag forces a line break

wherever you place it Does not have a closing </br> tag

Page 16: AK  html

HTML | Atul Kahate 16

Line Breaks Example<p>This <br> is a para<br>graph

with line breaks</p>

Page 17: AK  html

HTML | Atul Kahate 17

Comments The comment tag is used to insert a

comment in the HTML source code A comment will be ignored by the

browser You can use comments to explain

your code, which can help you when you edit the source code at a later date

Page 18: AK  html

HTML | Atul Kahate 18

Comments Example<!-- This is a comment -->

Page 19: AK  html

General tips

Page 20: AK  html

HTML | Atul Kahate 20

General Tips – 1 Different browsers display the

same HTML text differently The display size also drives this The text will be reformatted every

time the user resizes the window Never try to format the text in your

editor by adding empty lines and spaces to the text

Page 21: AK  html

HTML | Atul Kahate 21

General Tips – 2 HTML will truncate the spaces in your

text Any number of spaces count as one Using empty paragraphs <p> to insert

blank lines is a bad habit Use the <br> tag instead

HTML automatically adds an extra blank line before and after some elements, like before and after a paragraph, and before and after a heading

Page 22: AK  html

HTML | Atul Kahate 22

Character Entities – 1 Some characters such as < have a

special meaning in HTML They cannot be used as they are,

inside text Character entities are used in their

place

Page 23: AK  html

HTML | Atul Kahate 23

Character Entities – 2 Made up of three parts

& Entity name or # and the ASCII value

of the character ;

Example &lt; or &#60; should be used in the

place of <

Page 24: AK  html

HTML | Atul Kahate 24

Common Entities

Result Description Entity Name Entity

Number

  non-breaking space &nbsp; &#160;

< less than &lt; &#60;> greater than &gt; &#62;& ampersand &amp; &#38;" quotation mark &quot; &#34;' apostrophe  &apos; &#39;

Page 25: AK  html

HTML | Atul Kahate 25

Anchor Tag and Href Attribute The anchor tag can be used to

create a link to another document Called as hyperlink or URL The tag is <a>

Page 26: AK  html

HTML | Atul Kahate 26

Anchor Tag and Href Attribute Syntax

<a href="url">Text to be displayed</a> a = Create an anchor href = Target URL Text = Text to be displayed as substitute for

the URL Example

<a href="http://www.yahoo.com/">Visit Yahoo!</a>

Result: visit Yahoo!

Page 27: AK  html

HTML Tables

Page 28: AK  html

HTML | Atul Kahate 28

TablesTag Use<table> Marks a table within an HTML

document.<tr> Marks a row within a table.

<td> Marks a cell (table data) within a row.

<th> Marks a heading cell within a row.

Page 29: AK  html

HTML | Atul Kahate 29

Table Exercise Create the following HTML table

Book Name AuthorComputer Networks TanenbaumTCP/IP ComerTCP/IP Protocol Suite Forouzan

Page 30: AK  html

HTML | Atul Kahate 30

Solution – 1 Start with the <table> and </table> tags

<table></table>

Add <tr> tags between the boundaries noted above for each row.<table><tr></tr><tr></tr><tr></tr><tr></tr></table>

Page 31: AK  html

HTML | Atul Kahate 31

Solution – 2 Add <th> tags for the headings

<table><tr>

<th></th><th></th>

</tr><tr></tr><tr></tr><tr></tr></table>

Page 32: AK  html

HTML | Atul Kahate 32

Solution – 3 Add <td> tags for the data

<table><tr>

<th></th><th></th>

</tr><td></td><td></td>

<tr><td></td><td></td>

</tr><tr>

<td></td><td></td>

</tr></table>

Page 33: AK  html

HTML | Atul Kahate 33

Solution – 4 Add the element for each cell, including headers

<table><tr>

<th>Book Name</th><th>Author</th>

</tr><tr>

<td>Computer Networks</td><td>Tanenbaum</td>

</tr><tr>

<td>TCP/IP</td><td>Comer</td>

</tr><tr>

<td>TCP/IP Protocol Suite</td><td>Forouzan</td>

</tr></table>

Page 34: AK  html

HTML | Atul Kahate 34

Exercises1. How would add rows to this

table?2. How would add columns to this

table?

Page 35: AK  html

HTML | Atul Kahate 35

Solutions1. Add one more <tr> and </tr>

pair.2. Add one more <th> and </th>

pair.

Page 36: AK  html

HTML | Atul Kahate 36

Table ExampleHTML Code<table border="1"><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>Output

row 1, cell 1 row 1, cell 2 row 2, cell 1 row 2, cell 2

Page 37: AK  html

HTML | Atul Kahate 37

Table HeadingsHTML Code<table border="1"><tr><th>Heading</th><th>Another Heading</th></tr><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>

Output

Heading Another Heading

row 1, cell 1 row 1, cell 2 row 2, cell 1 row 2, cell 2

Page 38: AK  html

HTML | Atul Kahate 38

Spanning Rows and Columns Spanning means stretching a cell

over multiple rows or columns Example

Publisher Book Name AuthorComputer Networks Tanenbaum

Pearson TCP/IPComer

Modern Operating SystemsTanenbaum

Page 39: AK  html

HTML | Atul Kahate 39

HTML Syntax for SpanningAttribute UseRowspan=n Used in <td> or <th> tags,

indicates how many rows the cell should span. For example, rowspan=3 spans three rows.

Colspan=n Used in <td> or <th> tags, indicates how many columns the cell should span. For example, colspan=3 spans three columns.

Page 40: AK  html

HTML | Atul Kahate 40

Exercise Create the following HTML table

Publisher Book Name AuthorComputer Networks Tanenbaum

Pearson TCP/IPComer

Modern Operating SystemsTanenbaum

Page 41: AK  html

HTML | Atul Kahate 41

Solution – 1 Start with the basic HTML table

<table><tr>

<th>Book Name</th><th>Author</th>

</tr><td>Computer Networks</td><td>Tanenbaum</td>

<tr><td>TCP/IP</td><td>Comer</td>

</tr><tr>

<td>TCP/IP Protocol Suite</td><td>Forouzan</td>

</tr></table>

Page 42: AK  html

HTML | Atul Kahate 42

Solution – 2 Add a new column for the Publisher title and name: Output would be distorted at

this stage<table><tr>

<th>Publisher</th><th>Book Name</th><th>Author</th>

</tr><tr>

<td>Pearson</td><td>Computer Networks</td><td>Tanenbaum</td>

</tr><tr>

<td>TCP/IP</td><td>Comer</td>

</tr><tr>

<td>TCP/IP Protocol Suite</td><td>Forouzan</td>

</tr></table>

Page 43: AK  html

HTML | Atul Kahate 43

Solution – 3 Add rowspan attribute to the <th> or <td> tag that we want to span across

rows<table><tr>

<th>Publisher</th><th>Book Name</th><th>Author</th>

</tr><tr>

<td rowspan=3>Pearson</td><td>Computer Networks</td><td>Tanenbaum</td>

</tr><tr>

<td>TCP/IP</td><td>Comer</td>

</tr><tr>

<td>TCP/IP Protocol Suite</td><td>Forouzan</td>

</tr></table>

Page 44: AK  html

HTML | Atul Kahate 44

Exercise Create the following table

Organization Project Completion %FCIB 90%

i-flex GCB 50%ADCB 95%

Page 45: AK  html

HTML | Atul Kahate 45

Column Spanning Create the following table

structureBook Descriptive information

Type Name Price ClassificationC++ 100 Language

Ref Java 200 LanguageWeb Tech 250 Concepts

Page 46: AK  html

HTML | Atul Kahate 46

Solution – 1 Start with the following<table><tr>

<th>Type</th><th>Name</th><th>Price</th><th>Classification</th>

</tr><tr>

<td rowspan=3>Ref</td><td>C++</td><td>100</td><td>Language</td>

</tr><tr>

<td>Java</td><td>200</td><td>Language</td>

</tr><tr>

<td>Web Tech</td><td>250</td><td>Concepts</td>

</tr></table>

Page 47: AK  html

HTML | Atul Kahate 47

Solution – 2 Add a <TR> tag with <TH> for spanning<table><tr>

<th>Book</th><th>Descriptive information</th>

</tr><tr>

<th>Type</th><th>Name</th><th>Price</th><th>Classification</th>

</tr><tr>

<td rowspan=3>Ref</td><td>C++</td><td>100</td><td>Language</td>

</tr><tr>

<td>Java</td><td>200</td><td>Language</td>

</tr><tr>

<td>Web Tech</td><td>250</td><td>Concepts</td>

</tr></table>

Page 48: AK  html

HTML | Atul Kahate 48

Solution – 3 Add <colspan> attribute for spanning<table><tr>

<th colspan=2>Book</th><th colspan=2>Descriptive information</th>

</tr><tr>

<th>Type</th><th>Name</th><th>Price</th><th>Classification</th>

</tr><tr>

<td rowspan=3>Ref</td><td>C++</td><td>100</td><td>Language</td>

</tr><tr>

<td>Java</td><td>200</td><td>Language</td>

</tr><tr>

<td>Web Tech</td><td>250</td><td>Concepts</td>

</tr></table>

Page 49: AK  html

HTML | Atul Kahate 49

Table Colors, Alignment <TABLE BGCOLOR = “…”> allows

us to specify the background color <TR ALIGN> allows specifying the

text alignment

Page 50: AK  html

Text Colors

Page 51: AK  html

HTML | Atul Kahate 51

Setting Text Colors Use the <TEXT = “Color”> tag

Example <BODY TEXT = “BLUE”>

Use the <FONT> tag Set font size, color, face (style) Example

<FONT FACE = “Comical” SIZE = “+2” COLOR = “RED”> Look at this! </FONT>

Page 52: AK  html

HTML Lists

Page 53: AK  html

HTML | Atul Kahate 53

Lists Two types

Unordered List of items marked with bullets Starts with <ul>, each item starts with

<li> Ordered

List of items marked with numbers Starts with <ol>, each item starts with

<li>

Page 54: AK  html

HTML | Atul Kahate 54

Allowed “types” in Lists Numbered lists

Type=“A”Number or letter with which the list should start; other options are a, I, i, or 1 (Default)

Bulleted lists Type=“disc” Bullet type to be used; other

options are square and circle

Page 55: AK  html

HTML | Atul Kahate 55

Unordered List ExampleHTML code<ul><li>Coffee</li><li>Milk</li></ul>

Output• Coffee • Milk

Page 56: AK  html

HTML | Atul Kahate 56

Another Unordered List Example

HTML code<ul type=“square”><li>Coffee</li><li>Milk</li></ul>

Output Coffee Milk

Page 57: AK  html

HTML | Atul Kahate 57

Ordered List ExampleHTML code<ol><li>Coffee</li><li>Milk</li></ol>

Output1. Coffee 2. Milk

Page 58: AK  html

HTML | Atul Kahate 58

Another Ordered List Example

HTML code<ol type=“A”><li>Coffee</li><li>Milk</li></ol>

OutputA. Coffee B. Milk

Page 59: AK  html

HTML | Atul Kahate 59

Nested List ExampleHTML code<html><body>

<h4>A nested List:</h4><ul> <li>Coffee</li> <li>Tea <ul> <li>Black tea</li> <li>Green tea</li> </ul> </li> <li>Milk</li></ul>

</body></html>

Page 60: AK  html

HTML | Atul Kahate 60

Output of Nested List Example• Coffee • Tea

o Black tea o Green tea

• Milk

Page 61: AK  html

HTML Forms

Page 62: AK  html

HTML | Atul Kahate 62

Forms Form is an area containing form

elements A form element allows user to enter

information Text fields Drop-down buttons Radio buttons Checkboxes

<form> and </form> tags are used

Page 63: AK  html

HTML | Atul Kahate 63

<input> tag Most commonly used form element Type of input is specified with the

type attribute Concept

<form><input type=“text” …>…</form>

Page 64: AK  html

HTML | Atul Kahate 64

Input field tag and attributesTag/Attribute

Use

<input> Sets an area in a form for user inputType=“…” Text, Password, Checkbox, Radio, File, Hidden,

Image, Submit, ResetName=“…” Processes form resultsValue=“…” Provide default valuesSize=“n” Sets visible size for text inputsMaxlength=“n”

Maximum input size for text fields

Selected Default selection when form is initially displayed or reloaded

Page 65: AK  html

HTML | Atul Kahate 65

Forms Example – Textboxes<form>First name: <input type="text" name="firstname"><br>Last name: <input type="text" name="lastname"></form>

Output:

First name:

Last name:

Page 66: AK  html

HTML | Atul Kahate 66

Forms Example – Radio Buttons<form><input type="radio" name=“fruit" value=“apple"> Apple<br><input type="radio" name=“fruit" value=“orange"> Orange</form>

Output:

o Appleo Orange

Page 67: AK  html

HTML | Atul Kahate 67

Forms Example – Checkboxes<form><input type="checkbox" name=“vehicle“ value=“bike”>I have a bike<br><input type="checkbox" name=“vehicle“ value=“car”>I have a car</form>

Output:

I have a bike I have a car

Page 68: AK  html

HTML | Atul Kahate 68

Forms Example – Submit Buttons<form name="input" action="html_form_action.asp“ method="get"> Username: <input type="text" name="user">

<input type="submit" value="Submit"></form>

Output:

Username: Submit

Page 69: AK  html

HTML | Atul Kahate 69

Forms Example – Dropdown Boxes<form><select name="cars"><option value="volvo">Volvo<option value="saab">Saab<option value="fiat">Fiat<option value="audi">Audi</select></form>

Output:

A dropdown box showing these four car names

Page 70: AK  html

HTML | Atul Kahate 70

Exercise Create the following form with guidelines

as specified below. Fields in the form should be first name, last

name, email, address, city, state, pin, and country

All text fields except City should have display length of 40 and maximum length of 50

City should have display length of 20 and maximum length of 40

State should have the following set of values to choose from: AP, Bi, Ma, MP, TN

Page 71: AK  html

HTML | Atul Kahate 71

Solution<html><body>

<title> Forms Example </title>

<form><input type="text" name="firstname" size="40" maxlength="50">First Name<br><input type="text" name="lastname" size="40" maxlength="50">Last Name<br><input type="text" name="email" size="40" maxlength="50">Email Address<br><input type="text" name="address" size="40" maxlength="50">Postal Address<br><input type="text" name="city" size="20" maxlength="40">City<select name="state"><option value="ap">AP<option value="bi">Bi<option value="ma">MH<option value="mp">MP<option value="mp">TN</select>State<input type="text" name="pin" size="10" maxlength="15">Pin code<br><input type="text" name="country" size="40" maxlength="50">Country<br>

</body></html>

Page 72: AK  html

HTML | Atul Kahate 72

Text areas Used for multi-line

inputs Example:<textarea

name=“comments” rows=“5” cols=“40”> Please provide comments</textarea>

Tag/Attribute

Use

<textarea> Area for multi-line user input

Name=“…” Name for the text area

Rows=“n” Number of visible rows

Cols=“n” Number of visible rows

Page 73: AK  html

HTML | Atul Kahate 73

Formatting Forms <html>

<head> <title>Formatted Form Example</title> </head>

<body> <form action="donothing.jsp" metod="POST">

<table border="2">

<tr> <th>Choose your payment mechanism:</th> <td> <select name="paymentmode"> <option value="creditcard">Credit Card</option> <option value="debitcard">Debit Card</option> </select> </td> </tr>

<tr> <th align="left">Type:</th> <td> <input type="radio" name="cardtype" value="visa">Visa <br> <input type="radio" name="cardtype" value="master">Master <br> <input type="radio" name="cardtype" value="other">Other </td> </tr>

</table> </form> </body> </html>

Page 74: AK  html

Images

Page 75: AK  html

HTML | Atul Kahate 75

Images The <img> tag is used The <src> tag specifies the URL of the

image we want to display Syntax

<img src="url"> The ‘alt’ attribute is used to define

alternate text for an image, in case the image is not found e.g. <img src="boat.gif" alt="Big Boat">

Page 76: AK  html

HTML | Atul Kahate 76

Image Example<html><body>

<h3>Image Example</h3>

<img src="crypto.jpg">

</body></html>

Page 77: AK  html

HTML | Atul Kahate 77

Sizing Images We can set the width and height of

images in pixels Example:

<img src=“crypto.jpg” width=“800” height=“400”>

Page 78: AK  html

HTML | Atul Kahate 78

Adding Background Images<html><body background="background.jpg">

<h3>Look: A background image!</h3>

<p>Both gif and jpg files can be used as HTML backgrounds.</p>

<p>If the image is smaller than the page, the image will repeat itself.</p>

</body></html>

Page 79: AK  html

Stylesheets

Page 80: AK  html

HTML | Atul Kahate 80

Formatting Nightmares The original HTML was never intended to

contain tags for formatting a document HTML tags were intended to define the

content of the document like: <p>This is a paragraph</p> <ul>This is an unordered list</ul>

When tags like <font> and color attributes were added to the HTML 3.2 specification, it started a nightmare

A long, expensive and unduly painful process!

Page 81: AK  html

HTML | Atul Kahate 81

Enter HTML 4.0 All formatting can be moved out of

the HTML document and into a separate style sheet

Separation of the presentation of the document from its structure

Total control of presentation layout without messing up the document content

Page 82: AK  html

HTML | Atul Kahate 82

One css, Many html documents

Corporate.css

Document1.html

Document2.html

Document3.html

Document4.html

Page 83: AK  html

HTML | Atul Kahate 83

Styles When a browser comes across a

style sheet, it formats the document according to it

Three ways External style sheet Internal style sheet Inline style sheet

Page 84: AK  html

HTML | Atul Kahate 84

External Style Sheet Ideal when the style is applied to many

pages With an external style sheet, you can

change the look of an entire Web site by changing one file

Two methods to use such a style sheet Each page must link to the style sheet using the

<link> tag The <link> tag goes inside the head section

Use the @import directive

Page 85: AK  html

HTML | Atul Kahate 85

External Style Sheet Example: Using link Allows different style sheets to be used

with one HTML (e.g. view.css, print.css) One of these would be used, depending

on the requirement

<head><link rel="stylesheet" type="text/css"href=“view.css"> <!--(OR “print.css”) --></head>

Page 86: AK  html

HTML | Atul Kahate 86

External Style Sheet Example: Using import Multiple style sheets, each one having

a separate function (e.g. one for organization, one for department, …)

<HEAD><STYLE>@import url (“red.css”)@import url (“green.css”)</STYLE>

Page 87: AK  html

HTML | Atul Kahate 87

Internal Style Sheet Should be used when a single

document has a unique style You define internal styles in the

head section with the <style> tag

Page 88: AK  html

HTML | Atul Kahate 88

Internal Style Sheet Example<head><style type="text/css">body {background-color: red}p {margin-left: 20px}</style></head>

Page 89: AK  html

HTML | Atul Kahate 89

Inline Style Sheet Should be used when a unique

style is to be applied to a single occurrence of an element

To use inline styles you use the style attribute in the relevant tag

The style attribute can contain any CSS property

Page 90: AK  html

HTML | Atul Kahate 90

Inline Style Sheet Example<p style="color: red; margin-left:

20px">This is a paragraph</p>

Page 91: AK  html

HTML | Atul Kahate 91

HTML Head The head element contains general information,

also called meta-information, about a document Meta means "information about" Meta-information means information about

information Elements inside the Head element are not

displayed by the browser According to the HTML standard, only a few tags

are legal inside the head section: <base>, <link>, <meta>, <title>, <style>, and <script>

Page 92: AK  html

HTML | Atul Kahate 92

HTML URLs Uniform Resource Locator (URL) is used to

address a document (or other data) on the World Wide Web

scheme://host.domain:port/path/filename Scheme: Type of Internet service. The most

common type is http. Domain: The Internet domain name, e.g.

yahoo.com. Host: The domain host (default is www) :Port: The port number at the host (Default 80) Path: Path (a sub directory) on the server Filename: The name of the document

Page 93: AK  html

HTML | Atul Kahate 93

HTML URL Examples Email

<a href="mailto:[email protected]">[email protected]</a>

Page 94: AK  html

JavaScript: Introduction

Page 95: AK  html

HTML | Atul Kahate 95

HTML Scripts Scripts make static HTML pages

interactive <script> tag is used Browsers are programmed to

interpret scripts

Page 96: AK  html

HTML | Atul Kahate 96

Script Example<html><head></head><body><script type="text/javascript">document.write("Hello World!")</script></body></html>Output:

Hello World!

Page 97: AK  html

HTML | Atul Kahate 97

Handling Old Browsers Old browsers that cannot interpret

scripts will display the scripting code on the screen!

To prevent this, we can comment out the scripting code Old browsers would ignore scripts Newer browsers would interpret and

execute the scripts, as expected See next slide

Page 98: AK  html

HTML | Atul Kahate 98

Handling Old Browsers – Code JavaScript:

<script type="text/javascript"><!-- document.write("Hello World!") //--></script>

VBScript:<script type="text/vbscript"><!-- document.write("Hello World!") '--></script>

Page 99: AK  html

Thank you!

Questions and Comments Welcome!