Layers Frames

34

description

 

Transcript of Layers Frames

Page 1: Layers Frames
Page 2: Layers Frames

Layer positioning Properties of layers Using layers Nesting layers Layers and tables Formatting via layers

Page 3: Layers Frames

Layers are simple to use and less restrictive Layer nesting is simpler than table nesting Tables use 5 tags for hierarchical structure

whereas Layer just uses 1 tag for everything Div Layers provide better control over

formatting and layout

Page 4: Layers Frames

XHTML provides the <div> and the <span> tags to create layers (document sections)• <layer> and <ilayer> are obsolete

<div> - defines cascading style sheets (CSS) block layers

<span> - another tag to create layers in-line

Page 5: Layers Frames

A layer is a rectangular container (region) that holds XHTML content and can be positioned anywhere on a web page

Layer is placed using pixel coordinates, or at a percentage of its containing layer’s dimensions (e.g. 20% of the width in from the left edge)

Layers organize and format page content

Initial layers get covered by new layers (z-index)

Page 6: Layers Frames

The important properties are:

• ID – specifies layer name• Positioning – what is layer positioned relative to?• Location (left,top) – measured relative to top left

corner • Size (height,width) – specifies width and height • Visibility – specifies whether a layer is hidden or

visible• Background color/image – a colour/image can be

assigned to a layer• Z-index – represents its order of stacking • Clip –limits a layers’ displayable area• Overflow –what to do if content exceeds layer’s size

Page 7: Layers Frames

Clip the (absolutely positioned) layer so that only some of it is visible.

Layer

Clip: rect(T, R, B, L)

T

L R

B

Page 8: Layers Frames

Appearance of layer content depends on the order of stacking

Webpage

Layer 1 (z-index = 1)

Layer 2 (z-index = 2)

Page 9: Layers Frames

Positioning is achieved using relative or absolute attributes

Positioning is referenced from the parent layer or browser window

Relative – relative to where the layer should be

Absolute – removes the layer from the reference frame

Page 10: Layers Frames

Reference frame is from the top left corner

(0,0)

(x2,y2)

(x1,y1)

Webpage

Layer 1

Layer 2

+X

+Y

Page 11: Layers Frames

Normal

Layer 1

Layer 2 willsit below Layer 1

Layer 2

Layer 3Layer 3

Page 12: Layers Frames

Relative

Layer 1

Layer 2 willsit below Layer 1

Layer 2

Layer 3Layer 3

Page 13: Layers Frames

Absolute

Layer 1

Layer 2 willsit below Layer 1Layer 2

Layer 3Layer 3

Page 14: Layers Frames

<div id="Layer 1" style="position:absolute; width:300px; height:75px; left:54px; top:15px; background-color:green"><b>This is layer 1</b></div> <div id="Layer 2" style="position:absolute; width:200px; height:65px; left:54px; top:60px; background-color:orange; border:1px”>This is layer 2</div>

This is a layer 1

This is a layer 2

(0,0) *

**Note all format details are in “style attribute”

Page 15: Layers Frames

A nested layer is a layer inside another layer Nesting layers allows better format and control of

web page layout A nested layer inherits the visibility of its parent

layer Nesting layers is not as complicated as table nesting Example: 3-level nesting

<div><div>

<div> Content goes here.</div>

</div> </div>

Page 16: Layers Frames

<div id="Layer 1" style="position:absolute; width:300px; height:75px; left:54px; top:15px; background-color:green">

<b>This is layer 1</b>

<div id="Layer 2" style="position:relative; width:200px; height:65px; left:54px; top:60px; background-color:orange; border:1px”>

This is layer 2</div>

</div>

This is a layer 1

This is a layer 2

(0,0) *

Page 17: Layers Frames

Formatting via layers is based on the idea of nesting layers

Each layer can be viewed as an independent region that can hold any XHTML content

The web page is divided into regions according to its layout

Each region is then substituted by a layer

Page 18: Layers Frames
Page 19: Layers Frames

Frame layout and design Frame sets and nesting Using frames Target frames and windows

Page 20: Layers Frames

Web pages that do not use tables, layers or frames tend to be left-side heavy

Frames divide a browser window into regions, with each region having its own web page

When a surfer clicks on a link, from a set of links, the browser displays the corresponding HTML file in a new web page, which may not have the same links, for further navigation – frames solve this

Page 21: Layers Frames

A frame is a rectangle that has a width and height, a location in a browser window, and content

A collection of frames is referred to as a frame set. It controls the layout of its frames

A frameset and a frame are created using the <frameset> and <frame> tags (+ <noframes>)

The <frameset> tag replaces <body> tag

Page 22: Layers Frames

Useful tips:

•Keep the frameset simple•Keep the frame’s content short•Keep the frames organised – use a driver frame

Page 23: Layers Frames

A frame set width is defined by number of columns, cols

A frame set height is defined by number of rows, rows

Units of rows and cols can be pixels or percentage of browser window

Page 24: Layers Frames
Page 25: Layers Frames

XHTML does not have a limit on the depth of frame nesting

However, one or two levels of nesting is all that is needed in practice

Page 26: Layers Frames
Page 27: Layers Frames

There are 4 XHTML tags that can be used:• <frameset> - Encloses all other frame tags

Attributes: rows, cols : rows, cols

• <frame> - Creates a frame in a frame set Attributes : name, src, noresize, scrolling, frameborder,

marginwidth, marginheight, longdesc

• <iframe> - Creates an inline frame Attributes : name, src, width, height, align, scrolling,

frameborder, longdesc, marginwidth, marginheight

• <noframes> - specifies alternative content for a browser Attributes: NO ATTRIBUTES

Page 28: Layers Frames

The <iframes> tag creates inline frames

An inline frame is a frame that is embedded inside the content of a Web page

No frame sets are required to create inline frames

Unlike the <frame> tag, the <iframe> tag is used inside the <body> tag

Page 29: Layers Frames

<frameset rows="*, *" cols="50%, *"><frame src="...."

name="myFrame1" frameborder="0"/> <frame src="...."

name="myFrame2" frameborder="0"/> <frame src="...."

scrolling="no"/> <frame src="...." noresize

marginwidth="0" marginheight="0"/>

</frameset>

Page 30: Layers Frames

<frameset cols="*, *"><frameset rows="*, *">

<frame src="...."/> <frame src="...."/>

</frameset>

<frame src="...."/> </frameset>

Page 31: Layers Frames

Frames optimize web page layout and facilitate navigation

Contents of some frames may never change and that of others may change frequently

Frames offer convenience to web surfers Target frames receive content from other frames Target frames must be given names when they

are created i.e. use name attribute of the <frame> tag

The source frame can then refer to a target frame source by its name i.e. use target name attribute

Page 32: Layers Frames
Page 33: Layers Frames

Example.htmlExample.html

<frameset cols=“*, 200"><frame src=“toc.html"/> <frame src=“initialContent.html name=“myTarget”/>

</frameset>

initialContent.htmlinitialContent.html

<i> Click any link in the above frame…. </i>

toc.htmltoc.html

<a href=http://www.neu.edu target=“myTarget”> NU programs </a><br/><a href=http://www.mit.edu target=“myTarget”>MIT programs </a><br/>

NU programs

MIT programs

NU programs

MIT programs

Click any link in the above frameClick any link in the above frame

Page 34: Layers Frames

Steven M. Schafer (2005), HTML, CSS, JavaScript, Perl, and PHP Programmer's Reference, Hungry Minds Inc,U.S.

Dan Cederholm (2005), Bulletproof Web Design: Improving Flexibility and Protecting Against Worst-Case Scenarios with XHTML and CSS, New Riders.

Ibrahim Zeid (2004), Mastering the Internet, XHTML, and Javascript