by: riham alsmari, pnu · using the id attribute 4 id names must be unique, if you assign the same...

42
BY: RIHAM ALSMARI, PNU Lab 3

Upload: others

Post on 18-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

BY: RIHAM ALSMARI, PNU

Lab 3

Page 2: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

LINKING

linking

Linking between documents

Linking to location within a document

Linking between document and specific location in other document

Linking to a web site

Linking to an E-mail address

Page 3: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Linking to Locations within Documents 3

To jump to a specific location within a document, you

first need to mark that location

One way to identify elements in an HTML document

is to use the id attribute

The id element uses the syntax:

id=“id ” where id is the id name assigned to the

element.

<h2 id=“H”>H</h2>

Page 4: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Using the id Attribute 4

Id names must be unique, if you assign the same id

to more than one element on your Web page, the

browser uses the first occurrence of the id name.

Id names are not case sensitive.

Page 5: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Linking to an id 5

Once you’ve marked an element using the id

attribute, you can create a hypertext link to that

element using the hypertext link

<a href = “#id”>content </a>

For example to create a link to h2 heading for the

letter A in the glossary document, you would enter

the following code:

<a href=“#A”>A</a>

Page 6: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Using the id Attribute for glossary.htm

6

<h1 style="color: blue">Glossary</h1>

<p>

[<a href="#A">A</a>] [<a href="#B">B</a>] [<a href="#C">C</a>]

[<a href="#D">D</a>] [<a href="#E">E</a>] [<a href="#F">F</a>]

[G] [H] [I]

[J] [K] [L]

[M] [N] [O]

[P] [Q] [R]

[S] [T] [U]

[V] [W] [X]

[Y] [Z]

</p>

Page 7: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Linking to Locations within Documents

7

Page 8: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

The id Attribute (top of page) 8

Use the id attribute to mark the top of the page <body>

<div id="top">

<img src="camshots.jpg" alt="CAMshots" />

</div>

… etc. …. Much more follows …

<hr />

<div><a href="#top">Return to Top</a> &#8657;</div>

<hr />

<address>

CAMshots &#8250;&#8250;&#8250; Advice and News from the World of Digital Photography by Patrick Healy

</address>

</body>

</html>

Page 9: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Creating Links between Documents 9

To create a link to a specific location in another file,

enter the code

<a href="reference#id">content</a>

where reference is a reference to an HTML or

XHTML file and id is the id of an element marked

within that file

<a href =“glossary.htm#D>”D” terms in

the Glossary</a>

Page 10: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Creating Links between Documents 10

Page 11: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Working with Linked Images & Image Maps

11

A standard practice on the Web is to turn the Web

site’s logo into a hypertext link pointing to the home

page

<a href="reference"><img src="file"

alt="text" /></a>

HTML also allows you to divide an image into

different zones, or hotspots, each linked to a

different destination

Page 12: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Working with Linked Images & Image Maps

12

Page 13: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Working with Linked Images & Image Maps

13

To define these hotspots, you create an image map

that matches a specified region of the inline image

to a specific destination

HTML supports two kinds of image maps: client-side

image maps and server-side image maps.

Page 14: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Client-Side Image Maps 14

A client-side image map is inserted in an image map into the HTML file, it is defined with the map element

<map id=“map” name = “map”>

Hotspots

</map>

Where map is the name of the image map and hotspots are the locations of the hotspots within the image.

You have to set id and name attribute to the same value.

Page 15: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Defining Hotspots on a Web Page 15

Define a hotspot using two properties:

Its location in the image

Its shape

Syntax of the hotspot element:

<area shape=“shape” coords=“coordinates”

href=“url” alt=“text” />

Shapes can be rectangles, circles, or polygons.

Page 16: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Creating a Rectangular Hotspot 16

Two points define a rectangular hotspot: the upper-left corner and the lower-right corner

A sample code for a rectangular hotspot is:

<area shape=“rect” coords=“x1,y1,x2,y2” …/>

Where x1,y1 are the coordinates of the the upper-left corner and x2,y2 are the coordinates of the the lower-right corner

<area shape=“rect” coords=“384,61,499,271”

href=“water.htm” alt=“water”/>

The hotspot is a hypertext link to water.htm

Page 17: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Creating a Circular Hotspot 17

A circular hotspot is defined by the location of its

center and its radius

<area shape=“circle” coords=“x,y,r”…/>

Where x and y are the coordinates of the center of

the circle and r is the circle’s radius.

<area shape=“circle” coords=“307,137,66”

href=“karts.htm” alt=“karts”/>

Coordinates are (307, 137), and it has a radius of 66

pixels

The hotspot is a hypertext link to page karts.htm

Page 18: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Creating a Polygonal Hotspot 18

To create a polygonal hotspot, you enter the coordinates for each vertex in the shape

<area shape=“poly” coords=“x1,y1,x2,y2,x3,y3,…”

.../>

• Where (x1,y1), (x2,y2), (x3,y3)and so forth define the coordinates of each corner in the multisided shape.

<area shape=“poly”

coords=“13,60,13,270,370,270,370,225,230,225,

230,60” href=“rides.htm” alt=“rides”/>

Coordinates are for each vertex in the shape

The hotspot is a hypertext link to rides.htm

With polygonal hotspot you can creates a wide variety of shapes as long as you know the coordinates of each corner.

Page 19: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Creating a Default Hotspot 19

<area shape="default" coords="0, 0, x, y" … />

where x is the width of the inline image in pixels

and y is the image’s height

Any spot that is NOT covered by another hotspot

will activate the default hotspot link

Page 20: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Applying an Image Map 20

To apply an image map to an image, add the

usemap attribute to the inline image’s <img> tag.

The syntax is

<img src=“file” alt=“text” usemap=“#map” />

Page 21: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Applying an Image Map 21

Page 22: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Creating a Client-Side Image Map 22

Page 23: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

23

Page 24: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Removing the border from an inline

image 24

To remove a border from an inline image, add the

following attribute to the <img> tag:

style = “border-width:0”

Example:

<img src="camshots.jpg" alt="CAMshots"

usemap="#logomap" style="border-width: 0" />

Page 25: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Introducing URLs 25

To create a link to a resource on the Internet, you

need to know its URL

A Uniform Resource Locator (URL) specifies the

precise location of a resource on the Internet

A protocol is a set of rules defining how information

is exchanged between two resources

Page 26: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Introducing URLs 26

Your Web browser communicates with Web servers

using the Hypertext Transfer Protocol (HTTP)

The URLs for all Web pages must start with the

scheme “http”

Other Internet resources use different protocols and

have different scheme names

Page 27: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Linking to a Web Site 27

To create a link to a Web site from your document,

use the URL of the Web site as the value of the href

attribute.

<a href="http://www.apogeephoto.com">Apogee

Photo</a>

Page 28: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Linking to an E-Mail Address 28

To create a hypertext link to an e-mail address, use the following syntax:

<a href="mailto:address">content</a>

Exampel:

<a href="mailto :[email protected]">E-mail us</a>

Page 29: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<a href=“Second.htm”> content </a>

Second.htm

second

First.htm

Page 30: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<h1 id=“A”> A: </h1>

A

First.htm

A:

-------------

A- using the id attribute:

B- linking to an id:

<a href=“#A”>A</a>

Page 31: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<h1 id=“A”> A: </h1>

A

First.htm

A- using the id attribute:

B- linking to an id:

<a href=“second.htm#A”>A</a>

Second.htm

A:

-------------

Page 32: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

google

First.htm

<a href=“http://www.google.com/”>google</a>

http://www.google.com/

Page 33: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

my e-mail

First.htm

<a href=“mailto: [email protected]”>my e-mail</a>

[email protected]

Page 34: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Image map

Client side

Server side

Page 35: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<map id=“map” name=“map”> hotspots </map>

A- insert imge map into the HTML file

Page 36: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<area shape=“rect” coords=“x1,y1,x2,y2” href=“second.htm” alt=“second”/>

B- defining hotspots

1- Rectangle Second.htm

(x1,y1)

(x2,y2)

Page 37: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<area shape=“circle” coords=“x,y,r” href=“second.htm” alt=“second”/>

B- defining hotspots

2- circular Second.htm

(x,y) r

Page 38: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<area shape=“poly” coords=“x1,y1,x2,y2,x3,y3”

href=“second.htm” alt=“second”/>

B- defining hotspots

3- polygonal Second.htm (x1,y1)

(x2,y2) (x3,y3)

Page 39: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<area shape=“default” coords=“0,0,x,y”

href=“second.htm” alt=“second”/>

B- defining hotspots

4- default Second.htm

Page 40: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<img scr=“filename” alt=“text” usemap=“#map”/>

C- apply an image map:

Page 41: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

<img scr=“filename” alt=“text” usemap=“#map”

style=“border-width:0”/>

Page 42: BY: RIHAM ALSMARI, PNU · Using the id Attribute 4 Id names must be unique, if you assign the same id to more than one element on your Web page, the browser uses the first occurrence

Lab Time