tutorial 4 creating special effects with css. selector patterns on a web page, elements are nested...

33
Tutorial 4 Creating Special Effects with CSS

Upload: emory-neal

Post on 16-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Tutorial 4Creating Special Effects with CSS

Page 2: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Selector PatternsOn a Web page, elements are nested

within other elements, forming a hierarchical tree structure

2

Nested within the <body> element.

Nested within <p> elements.

Nested within <span> element.

Page 3: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Selector PatternsCSS contextual selectors express the location of an

element

li b {color: blue} all <b> elements that are nested withn <li>

li b, h2 {color: blue} all <b> elements that are nested within <li> and also all <h2> elements

#note b {color: blue} all <b> elements that are nested within the element that has id=“note”

* {color: blue} all elements in the web page

p > b {color: blue} all <b> elements that are direct children of <p> elements.3 ( ** Not supported in IE7 )

Page 4: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Selector Patterns

.notes p {font-size: 8pt} all <p> elements that are nested within an element that has class=“notes”

.notes span {color: yellow} all <span> elements that are nested within an element that has class=“notes”

.notes a:hover {color: blue} all links that are nested within an element that has class=“notes” when the mouse hovers over the link

.notes {display: list-item} all elements that have class=“notes”

4 examples/052_pg-203-contextual-selector.htm

Page 5: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Selector Patterns

5

Page 6: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Working with Selector PatternsConditional comments allow you to apply

different HTML code for different versions of Internet Explorer<!-- [if condition IE version]>HTML code<![endif]-->

Different HTML code for different browsers that are NOT Internet Explorer

<!-- [if !IE]><!--> HTML code<![endif]-->

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e6

Page 7: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Applying Styles to ListsTo specify the list

marker displayed by the browser, you can apply the stylelist-style-type: type

7 examples/053_pg-208-list-styles.htm

Page 8: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Applying Styles to Lists

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e8

Page 9: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Applying Styles to ListsMost browsers place the list marker to the

left of the block, lining up the markers with each list itemlist-style-position: position

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e9

Page 10: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Working with ClassesThe class attribute is used when you want to identify

elements that share a common characteristic<elem class="class"> ... </elem>

You can use the class attribute to assign the same style to multiple elements sharing the same class value.class {styles}

10

class =“notes” is assigned to the <div>

These styles are applied to <a> elements nested within an element of class “notes”.

examples/053a_pg-213-classes.htm

Page 11: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Pseudo-Classes and Pseudo-ElementsA pseudo-class is a classification of an element

based on its current status, position, or use in the documentselector:pseudo-class {styles}

11

These styles are applied to <a> elements nested within an element of class “notes” when the mouse hovers over the link.

Page 12: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Using Pseudo-Classes

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e12 examples/054_pg-217-pseudo-classes-hover.htm

Page 13: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Using Pseudo-Classes and Pseudo-ElementsPseudo-elements are abstracted from

what we know of an element’s content, or position in the documentselector:pseudo-element {styles}

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e13

examples/054a_pg-221-pseudo-elements.htm

Page 14: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

New Perspectives on HTML, XHTML, and Dynamic

HTML, 4e14

•Go to my Web site and download the files for Tutorial 4

•http://www.kapple01.com/ccm/web2/home/web2_labdata.html

•Unzip the files into a work folder on your flash drive

•Go to pg 199 in text book and start the in-chapter exercise.

•Stop when you get to the end of the section on page 221

Page 15: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Positioning Objects with CSS

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e15

Page 16: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Positioning Objects with CSSCreate div containers for each element you want to positionEach element to be positioned should have a unique id

<div id=firstcol><p> Now that we have defined a div container and given it an ID, we are able to use styles to explicitly position it anywhere on the screen. </p>

<img src="images/pic1.gif" alt="temp">

<p> Anything contained within the div container, for instance these two paragraphs and image, can be positioned explicitly anywhere on the screen. We will see this in the upcoming slides </p>

</div>

#firstcol {position: absolute; left 100px; top 50px }New Perspectives on HTML, XHTML, and Dynamic HTML, 4e16

Page 17: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Positioning Objects with CSSCSS-P (CSS-Positioning) became part of the

specification for CSS2, and positioning styles were some of the first CSS2 styles to be adopted by browsersposition: type; top: value; right: value; bottom: value; left: value;

Absolute positioning enables you to place an element at specific coordinates either on a page or within a containing elementposition: absolute; left: 100px; top: 50px

Relative positioning is used to move an element relative to its default position on the pageposition: relative; left: 100px; top: 50px

17examples/054b-abs-rel-positioning.htm

Page 18: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Positioning Objects with CSS

18

Page 19: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Positioning Objects with CSS

“static” is the default position; it means the object is in it’s normal location in the flow of the document.

examples/055_pg-226-232-positioning-example1-original.htm

Page 20: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

position: absolute

20

“absolute” means the object’s position is specified relative to the position of its containing element. The containing element for “outer” is the body of the web page.

( original ) ( new )

50

50

Top edge of “outer” is 50px from the top of the page; left edge of “outer is 50px from the left edge of the page.

(Coordinates should have: px after them)

examples/060_pg-226-232-positioning-example2-absolute-outer.htm

Page 21: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

position: relative

21

( original ) ( new)

“relative” means the object’s position is specified relative to the position it would have occupied in the normal flow of the web page.

50

50

Top edge and left edge of “outer” are +50px from their places in the normal flow. ( same is true of “inner” )

50

50

(Coordinates should have: px after them)

examples/065_pg-226-232-positioning-example-3-relative-outer-and-inner.htm

Page 22: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Working with Overflow and Clipping

If you want to force an element into a specified height and width, you have to define how the browser should handle a situation where content overflows the space allotted to the objectoverflow: type

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e22

examples/070_pg-234-overflow.htm

Page 23: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Working with Overflow and ClippingThe clip style allows you to define a

rectangular region through which the element’s content can be viewedclip: rect(top, right, bottom, left)

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e23

examples/077_pg-236-clipping-images.htm

Page 24: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Stacking ElementsElements placed using CSS positioning are

stacked on top of elements that are notTo specify a different stacking order, use

the style:z-index: value

Higher z-index valuesdisplay in “front” of lower z-index values.

24

z-index is a style property:

examples/075_pg-238-z-index.htm

Page 25: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

New Perspectives on HTML, XHTML, and Dynamic

HTML, 4e25

•Go to pg 222 in text book and continue the in-chapter exercise.

•Stop when you get to the end of the section on page 239

Page 26: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Working with Different MediaBy default, a style sheet is applied to all devices,

and each device must determine how best to match the styles to its own requirements

CSS2 allows you to specify different styles for different Output devices with the media attribute in either the style element for embedded style sheets or the link element for external style sheets.

<style type="text/css" media="type">...</style>

or<link href="url" type="text/css" media="type" ... />

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e

26

Page 27: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Working with Different Media

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e27

Page 28: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Example:

28

The html file links to 2 style sheets: one for screen and another for print.

The <h2> element contains a nested <span>

element.

The style sheet for screen (scraps.css) includes these declarations.

Screen display is

like this

Page 29: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Example:

29

The html file links to 2 style sheets: one for screen and another for print.

The style sheet for print(scraps_print.css) includes these declarations.

Print display is like this

(** The “after” pseudo-element is not currently supported by IE? )

Page 30: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Hiding ElementsThe visibility style and the display style can be used to

keep an element from being displayed in the browservisibility: hidden hides the elementvisibility: display displays the elementdisplay: none hides the element

The difference between visibility and display is whether the element will take up space in the window.

30

visibility: hiddenDoes not show, but takes up space.

display: noneDoes not show, andtakes up no space.

Page 31: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Using Print Styles

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e31

CSS defines printed pages by extending the box model

Page 32: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

Using Print Styles

New Perspectives on HTML, XHTML, and Dynamic HTML, 4e32

The general rule to create and define a page box is:@page {styles}

Printed media can vary in size and orientation

The size style allows the Web author to define the default dimensions and orientation of the printed pagesize: width height orientation

Page 33: Tutorial 4 Creating Special Effects with CSS. Selector Patterns On a Web page, elements are nested within other elements, forming a hierarchical tree

New Perspectives on HTML, XHTML, and Dynamic

HTML, 4e33

•Go to pg 239in text book and continue work on the in-chapter exercise.