Top Banner
1 Introduction to Introduction to HTML II HTML II กกกกกกกกก กกกกกกกกกก กกกกกกกกก กกกกกกกกกก กกกกกกกกกกกกกกกกกกก กกกกกกกกกกกกกกกกกกก กกกกกกกกกกกกกกกกกกกกก กกกกกกกกกกกกกกกกกกกกก กกกกกกกกกกกกกกกกก กกกกก กกกกกกกกกกกกกกกกก กกกกก
60

1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ...

Dec 14, 2015

Download

Documents

Ezekiel Drover
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

1

Introduction to HTML IIIntroduction to HTML II

กนกวรรธน� เซี่�ยงเจ็�นกนกวรรธน� เซี่�ยงเจ็�นสำ��น�กว�ช�เทคโนโลยสำ�รสำนเทศและสำ��น�กว�ช�เทคโนโลยสำ�รสำนเทศและ

ก�รสำ��อสำ�รก�รสำ��อสำ�รมห�ว�ทย�ล�ยนเรศวร พะเย�มห�ว�ทย�ล�ยนเรศวร พะเย�

Page 2: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

2

ContentContent

HTML Forms and InputHTML Forms and Input HTMLHTML ImagesImages HTMLHTML BackgroundsBackgrounds HTMLHTML FontsFonts HTMLHTML StylesStyles HTMLHTML HeadHead

Page 3: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

3

ContentContent

HTMLHTML MetaMeta

HTML Uniform Resource LocatorsHTML Uniform Resource Locators

HTMLHTML ScriptsScripts

HTMLHTML WebWeb ServerServer

Page 4: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

4

HTML Forms and InputHTML Forms and Input A formA form is is an area that can contain form elements.an area that can contain form elements.

Form elements are elements that allow the user to Form elements are elements that allow the user to enter information (like text fields, textarea fields, enter information (like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.) drop-down menus, radio buttons, checkboxes, etc.) in a form.in a form.

A form is defined with the A form is defined with the <form><form> tag. tag.

<form><form> <input><input> <input><input></form> </form>

Page 5: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

5

HTML Forms and InputHTML Forms and InputForm Tags Form Tags Tag Description Tag Description <form><form> Defines a form for user input Defines a form for user input <input><input> Defines an input field Defines an input field <textarea><textarea> Defines a text-area (a multi-line Defines a text-area (a multi-line

text input control) text input control) <select><select> Defines a selectable list (a Defines a selectable list (a

drop-down box) drop-down box) <option><option> Defines an option in the Defines an option in the

drop-drop- down box down box <button><button> Defines a push buttonDefines a push button<legend><legend> Defines a caption for a Defines a caption for a

fieldsetfieldset<fieldset><fieldset> Defines a fieldset Defines a fieldset

Page 6: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

6

InputInput

The most used form tagThe most used form tag is the is the <input><input> tag. The type of input is specified with tag. The type of input is specified with the type attribute. the type attribute.

The most commonly used input types The most commonly used input types are explained below.are explained below.

Page 7: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

7

Text FieldsText Fields

Text fields are used when you want the user to type Text fields are used when you want the user to type letters, numbers, etc. in a form.letters, numbers, etc. in a form.

<form><form>

First name:First name: <input <input typetype="="texttext" " namename="="firstnamefirstname">">

<br><br>

Last name:Last name: <input <input typetype="="texttext" " namename="="lastnamelastname">">

</form></form>

Page 8: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

8

Text PasswordText Password

<form><form>UsernameUsername:: <input <input typetype="="texttext" " namename="="useruser"">><br><br>PasswordPassword::<input <input typetype="="passwordpassword" " namename=“=“pwdpwd"">><<//form>form>

<p><p>Note that when you type characters in a password Note that when you type characters in a password field, the browser displays asterisks or bullets field, the browser displays asterisks or bullets instead of the characters.instead of the characters.

</p></p>

Page 9: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

9

Text AreaText Area

<html><html><body><body><form><form>

<textarea <textarea rowsrows="="1010" " colscols="="3030">">The cat was playing in the garden.The cat was playing in the garden.</textarea></textarea>

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

Page 10: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

10

Radio ButtonsRadio Buttons

Radio ButtonsRadio Buttons are used when you want the are used when you want the user to user to select one of a limited number of choicesselect one of a limited number of choices..

<form><form>

<input <input typetype="="radioradio" " namename="="sexsex" " valuevalue="="malemale" >" >MaleMale

<br><br>

<input <input typetype="="radioradio" " namename="="sexsex" " valuevalue="="femalefemale">">FemaleFemale

</form></form>

Page 11: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

11

Radio ButtonsRadio Buttons

Radio ButtonsRadio Buttons are used when you want the are used when you want the user to user to select one of a limited number of choicesselect one of a limited number of choices..

<form><form>

<input <input typetype="="radioradio" " namename="="sexsex" " valuevalue="="malemale" " checkedchecked>>MaleMale

<br><br>

<input <input typetype="="radioradio" " namename="="sexsex" " valuevalue="="femalefemale">">FemaleFemale

</form></form>

Page 12: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

12

CheckboxesCheckboxes

CheckboxesCheckboxes are used when you want the are used when you want the user to user to select one or more options of a limited number of select one or more options of a limited number of choices.choices.

<form><form><input <input typetype="="checkboxcheckbox" " namename="="bikebike" > " > I have a bikeI have a bike<br><br><input <input typetype="="checkboxcheckbox" " namename="="carcar"> "> I have a carI have a car

</form></form>

Page 13: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

13

CheckboxesCheckboxes

CheckboxesCheckboxes are used when you want the are used when you want the user to user to select one or more options of a limited number of select one or more options of a limited number of choices.choices.

<form><form><input <input typetype="="checkboxcheckbox" " namename="="bikebike" " checkedchecked> > I have a bikeI have a bike<br><br><input <input typetype="="checkboxcheckbox" " namename="="carcar"> "> I have a carI have a car

</form></form>

Page 14: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

14

Drop-Down BoxDrop-Down Box

<form><form><select <select namename="="carscars">">

<option <option valuevalue=“=“11">">VolvoVolvo</option></option><option <option valuevalue=“=“22">">SaabSaab</option></option><option <option valuevalue=“=“33">">FiatFiat</option></option><option <option valuevalue=“=“44">">AudiAudi</option></option>

</select></select></form></form>

Page 15: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

15

Drop-Down BoxDrop-Down Box

<form><form><select <select namename="="carscars">">

<option <option valuevalue=“=“11">">VolvoVolvo</option></option><option <option valuevalue=“=“22">">SaabSaab</option></option><option <option valuevalue=“=“33" " selectedselected>>FiatFiat</option></option><option <option valuevalue=“=“44">">AudiAudi</option></option>

</select></select></form></form>

Page 16: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

16

List BoxList Box

<form><form>

<select <select namename="="carscars" " multiplemultiple>>

<option <option valuevalue="="volvovolvo">">VolvoVolvo</option></option>

<option <option valuevalue="="saabsaab">">SaabSaab</option></option>

<option <option valuevalue="="fiatfiat">">FiatFiat</option></option>

<option <option valuevalue="="audiaudi">">AudiAudi</option></option>

</select></select>

</form></form>

Page 17: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

17

List BoxList Box

<form><form>

<select <select namename="="carscars" " multiplemultiple>>

<option <option valuevalue="="volvovolvo">">VolvoVolvo</option></option>

<option <option valuevalue="="saabsaab">">SaabSaab</option></option>

<option <option valuevalue="="fiatfiat" " selectedselected>>FiatFiat</option></option>

<option <option valuevalue="="audiaudi">">AudiAudi</option></option>

</select></select>

</form></form>

Page 18: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

18

Legend and FieldSetLegend and FieldSet

<fieldset><fieldset><legend><legend>Health information:Health information:</legend></legend><form><form>

Height Height <input <input typetype="="texttext" " sizesize="3">="3">WeightWeight <input <input typetype="="texttext" " sizesize="3">="3">

</form></form></fieldset></fieldset>

<p><p>If there is no border around the input form, your If there is no border around the input form, your browser is too old.browser is too old.</p></p>

Page 19: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

19

The Form's Action Attribute and The Form's Action Attribute and the Submit Buttonthe Submit Button When the user clicksWhen the user clicks on the " on the "SubmitSubmit" "

button, button, the content of the form is sent to the content of the form is sent to another fileanother file. .

The form's action attributeThe form's action attribute defines defines the name the name of the file to send the content toof the file to send the content to. .

The file defined in the action attributeThe file defined in the action attribute usually does something with the received usually does something with the received input.input.

Page 20: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

20

The Form's Action Attribute and The Form's Action Attribute and the Submit Buttonthe Submit Button

<form <form actionaction= = ""receivereceive..phpphp"" methodmethod= = ""postpost"" > >

UsernameUsername: : <input <input typetype="="texttext" " namename="="useruser"">><input <input typetype="="submitsubmit" " valuevalue= "= "SendSend"">><input <input typetype= "= "resetreset" " valuevalue= "= "ClearClear"">>

<<//form>form>

Save: Save: send.phpsend.php

Page 21: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

21

ActionAction

actionaction เป็#นก�รก��หนดว%�จ็ะสำ%งค%�จ็�กเป็#นก�รก��หนดว%�จ็ะสำ%งค%�จ็�ก formform ป็&จ็จ็'บั�นไป็ให+ก�บั ป็&จ็จ็'บั�นไป็ให+ก�บั formform อ��นๆ เพ��อท��ก�รอ��นๆ เพ��อท��ก�รป็ระมวลผลต่%อไป็ป็ระมวลผลต่%อไป็

actionaction==““receive.phpreceive.php” ” ช��อช��อ receive.phpreceive.php ค�อช��อค�อช��อเว�บัเพจ็ท�เร�ต่+องก�รสำ%งข้+อม0ลท�ได+ร�บัก�รบั�นท1กจ็�กเว�บัเพจ็ท�เร�ต่+องก�รสำ%งข้+อม0ลท�ได+ร�บัก�รบั�นท1กจ็�ก form form ป็&จ็จ็'บั�นป็&จ็จ็'บั�น

send.phpsend.php receive.phpreceive.phpaction

ฟอร�มป็&จ็จ็'บั�นสำ%งข้+อม0ล

ฟอร�มท�ร�บัค%�จ็�ก action

Page 22: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

22

MethodMethod

method method ค�อว�ธในก�รสำ%งค%�ระหว%�งค�อว�ธในก�รสำ%งค%�ระหว%�ง formform ป็ระกอบัด+วยป็ระกอบัด+วย GETGET POSTPOST

Page 23: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

23

Method:GETMethod:GET methodmethod=“=“getget” ” เป็#นก�รสำ%งค%�ไป็ย�งเป็#นก�รสำ%งค%�ไป็ย�ง

เว�บัเพจ็เป็3�หม�ยท�ก��หนดไว+ โดยเว�บัเพจ็เป็3�หม�ยท�ก��หนดไว+ โดยจ็ะแสำดงจ็ะแสำดงร�ยละเอยดข้องข้+อม0ลท�สำ%งไป็ร�ยละเอยดข้องข้+อม0ลท�สำ%งไป็ผ%�นท�งผ%�นท�ง Address BarAddress Bar ข้องข้อง Web BrowserWeb Browser

Page 24: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

24

send_GET.phpsend_GET.php<form <form actionaction= = ""receive_GETreceive_GET..phpphp"" methodmethod= = ““getget"">>

UsernameUsername: :

<input <input typetype="="texttext" " namename="="useruser"">>

<input <input typetype="="submitsubmit" " valuevalue= "= "SendSend"">>

<input <input typetype= "= "resetreset" " valuevalue= "= "ClearClear"">>

<<//form>form>

Page 25: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

25

receive_GET.phpreceive_GET.php<<?php?php

$$user_nameuser_name = = $_GET$_GET['['useruser'];'];

echoecho "Receive user name is "Receive user name is $$user_nameuser_name";";

??>>

Page 26: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

26

Method: POSTMethod: POST methodmethod=“=“postpost” ” เป็#นก�รสำ%งค%�ไป็ย�ง เป็#นก�รสำ%งค%�ไป็ย�ง

เว�บัเพจ็เป็3�หม�ยท�ก��หนดไว+ โดยเว�บัเพจ็เป็3�หม�ยท�ก��หนดไว+ โดยจ็ะไม%จ็ะไม%แสำดงร�ยละเอยดข้องข้+อม0ลแสำดงร�ยละเอยดข้องข้+อม0ล

Page 27: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

27

send_POST.phpsend_POST.php<form <form actionaction= = ""receive_POSTreceive_POST..phpphp"" methodmethod= = ““postpost"">>

UsernameUsername: :

<input <input typetype="="texttext" " namename="="useruser"">>

<input <input typetype="="submitsubmit" " valuevalue= "= "SendSend"">>

<input <input typetype= "= "resetreset" " valuevalue= "= "ClearClear"">>

<<//form>form>

Page 28: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

28

receive_POST.phpreceive_POST.php<<?php?php

$$user_nameuser_name = = $_POST$_POST['['useruser'];'];

echoecho "Receive user name is "Receive user name is $$user_nameuser_name";";

??>>

Page 29: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

29

HTML ImagesHTML Images

Tag Tag Description Description

<img><img> Defines an image Defines an image

<map><map> Defines an image map Defines an image map

<area><area> Defines an area inside an image Defines an area inside an image map map

Page 30: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

30

The Image Tag and the Src The Image Tag and the Src AttributeAttribute

<html><html><body><body>

An imageAn image::

<img <img srcsrc="="PathPath ข้องแฟ3มร0ป็ข้องแฟ3มร0ป็" " widthwidth="="144144"" heightheight="="5050"">>

<<//body>body><<//html>html>

Page 31: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

31

The Image Tag and the Src The Image Tag and the Src AttributeAttribute

An image from another folder:An image from another folder:

<img <img srcsrc="="images/logo.gifimages/logo.gif" " widthwidth="="3333" " heightheight="="3232">">

An image from www.yahoo.com:An image from www.yahoo.com:

<img <img srcsrc="="http://www.yahoo.com/images/ie.gifhttp://www.yahoo.com/images/ie.gif" >" >

Page 32: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

32

Alternate TextAlternate Text<html><html><body><body>

<img <img srcsrc="="goleft.gifgoleft.gif" " altalt="="GoGo LeftLeft" " widthwidth="="3232" " heightheight="="3232">">

<p><p>Text-only browsers will only display the text in the "alt" Text-only browsers will only display the text in the "alt"

attribute, which is "Go Left".attribute, which is "Go Left".Note that if you hold the mouse pointer over the image it will Note that if you hold the mouse pointer over the image it will

display the text.display the text.</p></p>

</body></body></html></html>

Page 33: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

33

Link by ImageLink by Image

<html><html><body><body><p><p>You can also use an image as a link:You can also use an image as a link:

<a <a hrefhref="="lastpage.htmlastpage.htm">"><img <img borderborder="="00" " srcsrc="="buttonnext.gifbuttonnext.gif“>“></a></a>

</p></p>

</body></body></html></html>

Page 34: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

34

HTML BackgroundsHTML Backgrounds

The The <body><body> tag has two attributes tag has two attributes where you can specify backgrounds. where you can specify backgrounds. The background can be a color or an The background can be a color or an image.image.

Page 35: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

35

Backgrounds and bgcolorBackgrounds and bgcolor

The The bgcolorbgcolor attribute sets the attribute sets the background to a color. The value of this background to a color. The value of this attribute can be attribute can be a hexadecimal numbera hexadecimal number, , an an RRGGBB value, or a color name. value, or a color name.

<body<body bgcolorbgcolor="="#000000#000000"">>

<body<body bgcolorbgcolor="="rrggbb((00,,00,,00)")">>

<body<body bgcolorbgcolor="="blackblack"">>

Page 36: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

36

Backgrounds and bgcolorBackgrounds and bgcolor The background attribute sets the background The background attribute sets the background

to an image. The value of this attribute is the to an image. The value of this attribute is the URL of the image you want to use. If the image URL of the image you want to use. If the image is smaller than the browser window, the image is smaller than the browser window, the image will repeat itself until it fills the entire browser will repeat itself until it fills the entire browser window.window.

<body <body backgroundbackground="="clouds.gifclouds.gif">"><body <body backgroundbackground=“=“http://www.dee.com/clouds.gifhttp://www.dee.com/clouds.gif”>”>

Page 37: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

37

BackgroundBackground

<html><html><body <body backgroundbackground="="background.jpgbackground.jpg">">

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

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

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

</body></body></html></html>

Page 38: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

38

HTML Fonts AttributesHTML Fonts Attributes

Attribute Attribute Example Example PurposePurpose sizesize="="numbernumber" " sizesize="="22" " Defines the font size Defines the font size sizesize="="+number+number"" sizesize="="+1+1" " Increases the font Increases the font

size size sizesize="="-number-number" " sizesize="="-1-1" " Decreases the font Decreases the font

size size faceface="="face-nameface-name" " faceface= "= "ArialArial" " Defines the font-name Defines the font-name colorcolor="="color-valuecolor-value" " colorcolor="="#eeff00#eeff00" Defines the font color " Defines the font color colorcolor="="color-namecolor-name" " colorcolor="="redred" " Defines the font color Defines the font color

Page 39: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

39

HTML FontsHTML FontsWith HTML code like this, you can specify both the With HTML code like this, you can specify both the

size and the type of the browser output :size and the type of the browser output :<p><p><font <font sizesize="="22" " faceface="="VerdanaVerdana">">This is a paragraph.This is a paragraph.</font></font></p></p><p><p><font <font sizesize="="33" " faceface=“=“ArialArial">">This is another paragraph.This is another paragraph.</font></font></p> </p>

Page 40: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

40

HTML StylesHTML Styles

Tag Tag Description Description

<style><style> Defines a style definition Defines a style definition

<link><link> Defines a resource reference Defines a resource reference

<div><div> Defines a section in a document Defines a section in a document

<span><span> Defines a section in a Defines a section in a document document

Page 41: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

41

HTML StylesHTML Styles

When a browser reads a style sheet, it When a browser reads a style sheet, it will format the document according to will format the document according to it. There are three ways of inserting a it. There are three ways of inserting a style sheetstyle sheet::

External Style SheetExternal Style Sheet Internal Style SheetInternal Style Sheet Inline StylesInline Styles

Page 42: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

42

External Style SheetExternal Style Sheet

An external style sheet is ideal when the style is An external style sheet is ideal when the style is applied to many pages. With an external style applied to many pages. With an external style sheet, you can change the look of an entire Web sheet, you can change the look of an entire Web site by changing one file. Each page must link to site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag the style sheet using the <link> tag. The <link> tag goes inside the head section.goes inside the head section.

<head><head><link <link relrel="="stylesheetstylesheet" " typetype="="text/csstext/css“ “ hrefhref="="mystyle.cssmystyle.css">">

</head></head>

Page 43: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

43

Internal Style SheetInternal Style Sheet An internal style sheet should be used when a An internal style sheet should be used when a

single document has a unique style. You define single document has a unique style. You define internal styles in the head section with the internal styles in the head section with the <style> tag.<style> tag.

<head><head><style <style typetype="="text/csstext/css">">

bodybody { {background-colorbackground-color: : redred}}pp { {margin-leftmargin-left: : 20px20px}}</style></style>

</head> </head>

Page 44: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

44

Inline StylesInline Styles An inline style should be used when a unique style An inline style should be used when a unique style

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

To use inline styles you use the style attribute in the To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS relevant tag. The style attribute can contain any CSS property. The example shows how to change the property. The example shows how to change the color and the left margin of a paragraph:color and the left margin of a paragraph:

<p <p stylestyle="="colorcolor: : redred; ; margin-leftmargin-left: : 20px20px">">This is a paragraphThis is a paragraph</p></p>

Page 45: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

45

HTML HeadHTML Head The head element contains general The head element contains general

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

You can say that meta-data means You can say that meta-data means information about data, or meta-information information about data, or meta-information means information about information. means information about information.

Page 46: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

46

The elements inside the head The elements inside the head elementelement

The elements inside the head element should not be The elements inside the head element should not be displayed by a browser. displayed by a browser.

According to the HTML standard, only a few tags are According to the HTML standard, only a few tags are legal inside the head section. These are: <base>, legal inside the head section. These are: <base>, <link>, <meta>, <title>, <style>, and <script>. <link>, <meta>, <title>, <style>, and <script>.

Look at the following illegal construct: Look at the following illegal construct:

<head><head> <p><p>This is some textThis is some text</p></p></head> </head>

Page 47: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

47

HTML MetaHTML Meta Some search engines on the WWW will use the name and Some search engines on the WWW will use the name and

content attributes of the meta tag to index your pagescontent attributes of the meta tag to index your pages..

This meta element defines a description of your pageThis meta element defines a description of your page: : <meta <meta namename="="descriptiondescription" " contentcontent="="FreeFree WebWeb tutorialstutorials onon

HTML, CSS, XML, and XHTMLHTML, CSS, XML, and XHTML"">>

This meta element defines keywords for your pageThis meta element defines keywords for your page: : <meta <meta namename="="keywordskeywords" " contentcontent="="HTML, DHTML, CSS, XML, HTML, DHTML, CSS, XML,

XHTML, JavaScript, VBScriptXHTML, JavaScript, VBScript"">>

Page 48: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

48

HTML Uniform Resource HTML Uniform Resource LocatorsLocators UUniform niform RResource esource LLocatorsocators Something called a Uniform Resource Something called a Uniform Resource

Locator (Locator (URLURL) is used to address a document ) is used to address a document (or other data) on the World Wide Web. A full (or other data) on the World Wide Web. A full Web address like this: Web address like this: http://http://www.mysite.com/www.mysite.com/htmlhtml//lastpage.htm lastpage.htm follows these syntax rules:follows these syntax rules:

scheme://scheme://host.domainhost.domain::portport//pathpath/filename/filename

Page 49: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

49

URL SchemesURL Schemes Some examples of the most common schemes can Some examples of the most common schemes can

be found below:be found below:

Schemes Schemes Access Access filefile a file on your local PC a file on your local PC ftpftp a file on an FTP server a file on an FTP server httphttp a file on a World Wide Web Server a file on a World Wide Web Server gophergopher a file on a Gopher server a file on a Gopher server newsnews a Usenet newsgroup a Usenet newsgroup telnettelnet a Telnet connection a Telnet connection WAISWAIS a file on a WAIS servera file on a WAIS server

Page 50: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

50

HTML Uniform Resource HTML Uniform Resource LocatorsLocators The The schemescheme is defining the type of Internet is defining the type of Internet

service. The most common type is http. service. The most common type is http. The domain is defining the Internet The domain is defining the Internet domaindomain

name like name like mysite.commysite.com..

The The hosthost is defining the domain host. If is defining the domain host. If omitted, the default host for omitted, the default host for http is wwwhttp is www..

The The ::portport is defining the port number at the is defining the port number at the host. The port number is normally omitted. host. The port number is normally omitted. The default port number for The default port number for http is http is 8080. .

Page 51: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

51

HTML Uniform Resource HTML Uniform Resource LocatorsLocators The The pathpath is defining a path (a sub directory) is defining a path (a sub directory)

at the server. If the path is omitted, the at the server. If the path is omitted, the resource (the document) resource (the document) must be located at must be located at the root directory of the Web sitethe root directory of the Web site..

The The filenamefilename is defining the name of a is defining the name of a document. document. The default filename might be The default filename might be index.phpindex.php, or , or index.htmlindex.html or something else or something else depending on the settings of the depending on the settings of the Web serverWeb server..

Page 52: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

52

Accessing a NewsgroupAccessing a Newsgroup

The following HTML code:The following HTML code:

<a <a hrefhref="="newsnews::alt.htmlalt.html"> "> NewsgroupNewsgroup</a></a>

Page 53: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

53

Downloading with FTPDownloading with FTP

The following HTML code:The following HTML code:

<a <a hrefhref="="ftp://ftp://www.mysite.com/game.exewww.mysite.com/game.exe"> "> Download GameDownload Game

</a></a>

(The link doesn't work. Don't try it. It is just an (The link doesn't work. Don't try it. It is just an example. mysite doesn't really have an ftp example. mysite doesn't really have an ftp directory.)directory.)

Page 54: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

54

Link to your Mail systemLink to your Mail system

The following HTML code:The following HTML code:

<a <a hrefhref="="mailto:mailto:[email protected]@yahoo.com">"> [email protected]@yahoo.com

</a></a>

creates a link to your own mail system like creates a link to your own mail system like this:this:

Page 55: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

55

HTML ScriptsHTML Scripts A script in HTML is defined with the <script> A script in HTML is defined with the <script>

tag. Note that you will have to use the type tag. Note that you will have to use the type attribute to specify the scripting language.attribute to specify the scripting language.

<html><html><head></head><head></head><body><body>

<script<script typetype="="text/javascripttext/javascript"">> document.document.writewrite("("HelloHello World!World!")")</script></script>

</body></body></html> </html>

Page 56: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

56

HTML ScriptsHTML Scripts

Tag Tag Description Description

<script><script> Defines a script Defines a script

<noscript><noscript> Defines an alternate text if the Defines an alternate text if the script is not executed script is not executed

<object><object> Defines an embedded object Defines an embedded object

<param><param> Defines run-time settings Defines run-time settings (parameters) for an object (parameters) for an object

<applet><applet> Deprecated. Use <object> Deprecated. Use <object> instead instead

Page 57: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

57

HTML ScriptsHTML Scripts

JavaScriptJavaScript::<script<script typetype="="texttext//javascriptjavascript"">><<!--!--documentdocument..writewrite("("HelloHello WorldWorld!!")")//--//-->><<//script>script>

VBScriptVBScript::<script<script typetype="="texttext//vbscriptvbscript"">><<!--!--documentdocument..writewrite("("HelloHello WorldWorld!!")")''---->><<//script>script>

Page 58: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

58

<noscript><noscript>

JavaScriptJavaScript::

<script<script typetype="="texttext//javascriptjavascript"">>

<<!--!--

documentdocument..writewrite("("Hello WorldHello World!!")")

//--//-->>

<<//script>script>

<noscript><noscript>

Your browser does not support JavaScriptYour browser does not support JavaScript!!

<<//noscript> noscript>

Page 59: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

59

<noscript><noscript>

VBScriptVBScript::

<script<script typetype="="texttext//vbscriptvbscript"">>

<<!--!--

documentdocument..writewrite("("HelloHello WorldWorld!!")")

''---->>

<<//script>script>

<noscript><noscript>Your browser does not Your browser does not support VBScriptsupport VBScript!!<<//noscript>noscript>

Page 60: 1 Introduction to HTML II กนกวรรธน์ เซี่ยงเจ็น สำนักวิชาเทคโนโลยีสารสนเทศ และการสื่อสาร

60

HTML Web ServerHTML Web Server

Personal Web Server Personal Web Server ((PWSPWS)) Internet Information Server Internet Information Server ((IISIIS))Apache Apache ((LinuxLinux))Etc.Etc.