style sheets

105
1 Style Sheets Style Sheets DBI – Representation and Management of Data on the Internet

Upload: alina

Post on 13-Jan-2016

40 views

Category:

Documents


2 download

DESCRIPTION

Style Sheets. DBI – Representation and Management of Data on the Internet. What are Style Sheets?. Style sheets are a mechanism for allowing authors to specify how they wish documents written in a markup language, such as XML or HTML, to be formatted. Why HTML is not Enough?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Style Sheets

1

Style SheetsStyle Sheets

DBI – Representation and Management of Data on

the Internet

Page 2: Style Sheets

2

What are Style Sheets? What are Style Sheets?

• Style sheets are a mechanism for allowing authors to specify how they wish documents written in a markup language, such as XML or HTML, to be formatted

Page 3: Style Sheets

3

Why HTML is not Enough? Why HTML is not Enough?

• HTML gives only a limited control over the style of documentsFor Example, <H1>This Title</H1>

does not say how “This Title” should look like

We cannot specify a style for all the <H1> headers, such that this style can be defined once and applied to all <H1> headers at once

Page 4: Style Sheets

4

In AdditionIn Addition

• HTML doesn't offer sufficient control over document formatting, i.e., it doesn’t supportleading (the space between

lines)text shadowsand many other facets

Page 5: Style Sheets

5

The SolutionThe Solution

Style SheetDocuments

Documents with Style

Page 6: Style Sheets

6

HTML Style vs. XML StyleHTML Style vs. XML Style

XML

HTML

With CSS Style

CSSHTML

XSLXML

With XSL Style

Not all browsers

support all formats

Page 7: Style Sheets

7

Reasons to Use Style SheetsReasons to Use Style Sheets

• They separate content from formatting• They reduce download time by

removing formatting information from documents

• They give far more control over formatting than HTML

• They ensure a consistent appearance across a site

• One style sheet can be attached to many files (changes are easier)

Page 8: Style Sheets

8

What Reasons are there not to What Reasons are there not to use Style Sheets?use Style Sheets?

• Not all browsers fully support all style sheets

• Not all browsers support style sheets properly

• Be aware that since CSS (CSS2) is a large specification, most browsers do not support it in its entirety

Page 9: Style Sheets

9

What can be done in CSS?What can be done in CSS?

• Style sheets allow you to say, for example, that you want headings in 30px Arial

with a pink backgroundthat you want the whole document to

have a left margin of 1inand more, as will be shown next

Page 10: Style Sheets

10

ExampleExample

A definition in CSS:

BODY {color: red; background-color: white; font-size: 32px; font-family: Arial; line-height: 36px; margin-left: 5%}

Page 11: Style Sheets

11

Without StyleWithout Style

<HTML> <HEAD> CSS Test </HEAD> <BODY>

This is a test of using a CSS style sheet. <P>

</BODY></HTML>

Page 12: Style Sheets

12

On A BrowserOn A Browser

Page 13: Style Sheets

13

With StyleWith Style<HTML><HEAD><TITLE>Formatting style with CSS</TITLE><STYLE TYPE="text/css"><!-BODY {

color: red; background-color: white; font-size: 32px; font-family: Arial; line-height: 36px; margin-left: 5%}-></STYLE></HEAD><BODY>This is an example of using CSS.<P> </BODY></HTML>

Page 14: Style Sheets

14

On a BrowserOn a Browser

Page 15: Style Sheets

15

Using CSSUsing CSS

A Cascading Style Sheet

Page 16: Style Sheets

16

CSS - Cascading Style SheetCSS - Cascading Style Sheet

• CSS is a W3C recommendationfor formatting HTML and XML

documentsto simplify Web authoring and site

maintenance

• Level 1 (CSS1) from Dec. 1997• Level 2 (CSS2) from May 1998

Page 17: Style Sheets

17

CSS Level 1CSS Level 1

• Allows authors and readers to attach style (e.g., fonts, colors, spacing) to HTML/XML documents

• Implemented in “version 4.+” of major Web browsers (but not completely)

Page 18: Style Sheets

18

CSS Level 2CSS Level 2

• An extension of CSS1:has media-specific style sheets, e.g., for

aural/Braille/handheld devices, printers…Also supports

content positioning, downloadable fonts, table layout, internationalization, automatic counter and numbering

some properties related to user interface

Page 19: Style Sheets

19

CSS Style SheetCSS Style Sheet

• The style sheet is a set of style rules• A style rule syntax:

selector {declaration}

• selectorlocates elements affected by the rule

• declarationlooks like a list: P1:V1 ; … ; Pn:Vnsets values for formatting properties

Page 20: Style Sheets

20

Rules and PropertiesRules and Properties

• Example rulesH1 {color: blue}H1, H2, H3 {font-style:bold }P {font-family: verdana; color: red }

• Examples of formatting propertiesfont-size, font-style, font-family, font-

weight, font-align, margin-left, border-width, float, color, background-color, ...

Page 21: Style Sheets

21

Declaring Style DataDeclaring Style Data

• There are three ways to declare the style datain the <HEAD> of pagesat tag levelin a separate external style sheet

• In each case, style sheets do not contain any HTML, just style commands

Page 22: Style Sheets

22

External Style SheetsExternal Style Sheets

• Style sheets are linked using the tag <LINK rel="stylesheet” type="text/css” href="name.css"> which must go in the header of a page• Example<HTML> <HEAD> <LINK rel="stylesheet" type="text/css” href="fluorescent.css"> </HEAD> <BODY> ... </BODY></HTML>

Page 23: Style Sheets

23

Importing Style SheetsImporting Style Sheets• The @import rule allows you to keep some

things the same while having others different

• Usage: @import url(nameOfFile.css)• Reasons for using @import

If the documents include right-to-left text, and a bi-directional style is needed, one can use a standard bidi style sheet

If a standard style sheet specifies the appearance of most of the elements, but there are more specific elements that also need to be defined

Page 24: Style Sheets

24

Embedded Style sheetsEmbedded Style sheets• Embedded style sheets are enclosed in a <STYLE

type="text/css"> and </STYLE> tag• They go in the header of a page: <HTML> <HEAD> <STYLE type="text/css">

<!-- Note the HTML comment tags. BODY {color: red} They are for browsers that --> do not support style sheets. </STYLE> </HEAD> <BODY> ... </BODY> </HTML>

Page 25: Style Sheets

25

Inline StyleInline Style

• Any tag except the <HTML> tag itself can take the style attribute:

<P style="color: green"> and this is green</P>

will define the color of the paragraph to be green

Page 26: Style Sheets

26

DeclarationsDeclarations

• Declarations are used to apply style to elements, for example, to set an element to have a border

• The basic syntax of a declaration is a property (such as color) followed by a colon (:) and a value

• Declarations are directly used only in inline style

Page 27: Style Sheets

27

Declaration GroupingDeclaration Grouping

• In order to specify several styles for an element, declarations can be separated by semicolons

• It is optional to have a semicolon after the final declaration

• Example<P style="color: red; font-size: 16px">

Page 28: Style Sheets

28

SelectorsSelectors

• Selectors are used to associate style declarations with an element or elements

• Declarations are placed within a block (enclosed in {}) and preceded by a selector

• ExampleDIV {color: red; font-size: 16px}

Page 29: Style Sheets

29

Type vs. Class SelectorsType vs. Class Selectors

• There are type selectors and class selectors

• Type selectors are what we saw They give properties to elements

• Class selectors allow a user to give elements a particular name

• In HTML it looks as follows:<TAG class="classname">

Page 30: Style Sheets

30

Class SelectorsClass Selectors

• The definition of the class<P class="introductoryparagraph"> .... </P>

• The definition of the styleP.introductoryparagraph {color: blue}

applies to P elements with the class name introductorypargraph

.introductoryparagraph {color: blue} applies to any element with the class

name introductoryparagraph

Page 31: Style Sheets

31

Class Selectors (cont’d)Class Selectors (cont’d)

• An element may have more than one class, e.g., <P class="green quote new” matches, e.g.,

P.quote.green, P.new or P.quote.new.green, but not P.new.old.

• However, few browsers support this usage

Page 32: Style Sheets

32

Pseudo-Class SelectorsPseudo-Class Selectors

• Used for choosing values for properties based on the state of the browser

• :link and :visiteddifferent style for a visited link compared

to an unvisited one• :hover (the mouse is over the element) and

:focus (the focus is on the element)• :active (applied when an element is being

activated)

Page 33: Style Sheets

33

Pseudo-Class ExamplesPseudo-Class Examples

• A:link {color: red}

• A:visited {color: purple}

• P:hover {text-decoration: underline}

• A:focus {text-decoration: underline}

• INPUT:active {color: red}

Page 34: Style Sheets

34

Pseudo-Classes on LinksPseudo-Classes on Links• Suppose we are given the definition:

A:active {background-color: red}A:hover {background-color: yellow}A:link {background-color: green}

• What is the problem? • The states are not mutually

exclusive• A possible solution by multiple pseudo-

classes, i.e., A:link:hover• What will A:link:hover:focus {color: red} do?

Page 35: Style Sheets

35

Contextual SelectorsContextual Selectors

• If ELEMENT2 is a descendant of ELEMENT1, then the given properties apply to those ELEMENT2s

• Example STRONG EM {text-transform: uppercase}

/* EM inside STRONG will be uppercase */

<STRONG><EM>some text</EM></STRONG>

SOME TEXT

Page 36: Style Sheets

36

Selector GroupingSelector Grouping• Associate a block with several different

selectors • Save typing• Save download time • Done by separating the selectors by

commas• E.g., BODY P, H1 {color: red}

is the same as BODY P {color: red}

H1 {color: red}

Page 37: Style Sheets

37

The Universal Selector (*)The Universal Selector (*)

• The universal selector matches anything

• ExamplesBODY * P -- P is the grandchild or

greater of BODY*:active is equivalent to :active* {height: 100px} -- all elements should

be 100 pixels high

Page 38: Style Sheets

38

:First-Child Selector:First-Child Selector

• A pseudo-class

• Matches an element that is the first child of its parent

<OL><LI>This is the first child of OL -- it is matched by LI:first-child.<LI>This is the second child of OL.</OL>

Page 39: Style Sheets

39

Pseudo-Element SelectorsPseudo-Element Selectors

• Select part of an element (whereas pseudo-classes select all of the element)

• First-line and first-letter -- apply to the first line and the first letter of an element, respectively; Example:P:first-line {text-transform: capitalize}

P:first-letter {font-size: 48px; color: red}

Page 40: Style Sheets

40

ID SelectorsID Selectors

• IDs are identical to classes, except that there can only be one element with a given ID in a document.

• In the HTML document:<BODY id="introduction">

• In the style-sheet:BODY#introduction {font-size: 1.2em} or #introduction {font-size: 1.2em}

Page 41: Style Sheets

41

Attribute SelectorAttribute Selector• P[attribute]

matches P when attribute is set to any value

• P[title=intro] or P[title="intro"] (the quotes are optional) matches P when its title attribute set to

"intro"

• P[class~=green] matches P when the class attribute is set to

"green small", "small green", "green", etc.

Page 42: Style Sheets

42

CombinatorsCombinators

• Child combinators (>) - only apply to children (differently from contextual selectors)

• For example: BODY > P matches:

<BODY><P>

but not<BODY><DIV><P></DIV>

Page 43: Style Sheets

43

Adjacent Sibling Combinator (+)Adjacent Sibling Combinator (+)

• Used to specify that the two specified elements are adjacent siblings

<DIV><P> does not match P+P </P></DIV><P> does not match P+P </P><P> matches P+P </P>

Page 44: Style Sheets

44

ExampleExample<HTML><HEAD><TITLE>Formating style with CSS</TITLE></HEAD><BODY><IMG SRC="tomato.gif"><H1>A joke</H1><P> A mama tomato, a papa tomato and a baby tomato are walking down the street.The baby tomato keeps falling behind so the papa tomato goes back, steps on the baby tomato and says, ketchup ("Catch-up!").

</P> </BODY></HTML>

Page 45: Style Sheets

45

Page 46: Style Sheets

46

Adding a styleAdding a style<STYLE type="text/css">

BODY { background-image: url("tomato1.gif"); background-attachment: fixed

}H1 { background-color: rgb(100,150,100);

color: rgb(250, 200, 250);}P { background-color: yellow;

color: purple; font-size: 200%

}</STYLE>

Page 47: Style Sheets

47

Page 48: Style Sheets

48

<HEAD><TITLE>Some more style examples</TITLE></HEAD><style>

BODY {font-size: 30}P:first-line {color: #ff0000;font-variant: small-caps}

</style><BODY><SPAN style="float: left; font-size: 100px; line-height: 90px; width: 60px">T</SPAN>wo cows were walking together in a field. One turns to the other and says, "hey larry are you worried about getting that mad cow disease?"

<P>Larry, in a very odd and wacky voice says, <SPAN style="text-decoration: underline">"why would I, I'm a chicken?"</SPAN><SPAN style="text-decoration: line-through">"why would I, I'm a cow?"</SPAN></BODY></HTML>

Page 49: Style Sheets

49

Page 50: Style Sheets

50

Inheritance and CascadingInheritance and Cascading

Resolving Conflicts of Definitions

Page 51: Style Sheets

51

ConflictsConflicts

• Because CSS provides so many ways of applying style to pages, it is inevitable that declarations will conflict

• To resolve this, there is something known as a cascade

Page 52: Style Sheets

52

Inheritance and CascadingInheritance and Cascading• Properties are inherited by sub-elements

can be overriddencan be modified (e.g., increase indent, set

font size to 75% of current)

• “Cascading”style rules (from various sources) combinedconflicts resolved by a priority mechanism

rules with the most specific selector win

Page 53: Style Sheets

53

• Thus, if you specify BODY {color: red} then everything inside BODY will inherit that color unless a contrary declaration is made

<HEAD> <STYLE type="text/css"> <!-- BODY {color: red} --> </STYLE></HEAD> <BODY> <P>

InheritanceInheritance

Page 54: Style Sheets

54

Conflict ResolutionConflict Resolution

• In case of conflicting style definitions: the more specific one is chosen, e.g.,

P.warning {font-weight: bold} and .warning {font-weight: normal},

both would match <P class=“warning”>Watch out !</P>

but the first one winsthe one specified via a class overrides

normal ones, e.g., .warning {color: red} overrides P {color: blue}

Ids override classes

Page 55: Style Sheets

55

The Order SortThe Order Sort

• Rules at the end of the style sheet take precedence over those at the start

• Inline style is assumed to be read after embedded style, which is read after linked style

Page 56: Style Sheets

56

The Origin SortThe Origin Sort

• There are three possible sources of style: the author, the user (via a user style sheet), and the browser (via the browser's

style rules)

• Author > user > browser (> means override)

Page 57: Style Sheets

57

The Weight SortThe Weight Sort• Declarations - sorted according to weight • Declarations - can have normal weight or

important weight • Declarations are made important by the

addition of !important• The effect of the weight sort is:

to give that declaration greater weight than all others in its style sheet

to alter the origin sort (user style declarations that are !important override author ones, even if the author ones are also !important)

Page 58: Style Sheets

58

The Specificity SortThe Specificity Sort

• At last, the specificity sort prevails: (a) count the number of ids in the selector, (b) count the number of classes, attribute

selectors and pseudo-classes, (c) count the number of elements and pseudo-

elements Universal selectors have a specificity of 0

Make this into a number ABC - e.g.

BODY P[align]#hello:active:first-letter, has a=1, b=2, c=3 and thus we get 123.

• The highest number wins

Page 59: Style Sheets

59

The Order SortThe Order Sort

• Rules at the end of the style sheet > those at the start

• Inline style > embedded style > linked style

• Imported style sheets form the start of the importer's style sheet

Page 60: Style Sheets

60

CSS ConceptsCSS Concepts

Page 61: Style Sheets

61

CSS ConceptsCSS Concepts

• All CSS is case insensitive• Comments are enclosed in /* */• URLs can be used to import things

from the Web:url(http://www.background.com/back.jpg)

• Length can be specified relatively (px, em, ex, %), or absolutely (in, pt, mm, cm)

Page 62: Style Sheets

62

ColorsColors• There are 16 basic colors:Aqua Black Blue

Fuchsia Gray Green Lime Maroon Navy Olive Purple Red Silver Teal White Yellow

• Colors can also be specified as a hexadecimal number, e.g., #1CDBFA in this form: rgb (x%, y%, z%) (e.g. rgb (30%,

40%, 20%), or as a decimal number: rgb (x, y, z) (e.g. rgb

(168, 57, 32)), where the maximum and minimum on most computers is 255 and 0 respectively.

Page 63: Style Sheets

63

Colors (cont.)Colors (cont.)

• In order to make pages that conform to the operating environment that your users are used to, it is possible to declare all color values as one of the following:

• ActiveBorder, ActiveCaption, AppWorkspace, Background, ButtonFace, ButtonHighlight, ButtonShadow, ButtonText, CaptionText, GrayText, Highlight, HighlightText, InactiveBorder, InactiveCaption, InactiveCaptionText, InfoBackground, Menu, MenuText, Scrollbar, ThreeDDarkShadow, ThreeDFace, ThreeDHighlight, ThreeDLightShadow, Window, WindowFrame, WindowText

Page 64: Style Sheets

64

Colors ExampleColors Example

P {color: windowtext}BODY {color: #C67}LI {color: rgb(10%, 45%, 56.7%)}

Page 65: Style Sheets

65

FontsFonts

• Includes the properties: font-weight font-stretch font-variant font-style font-size-adjust font-size font-family

• Try it at home ...

Page 66: Style Sheets

66

TextText

• Has the propertiesVertical-alignText-alignText-decorationText-indentText-transformWord-spacing and letter-spacingWhite-spaceText-shadow

Page 67: Style Sheets

67

ListsLists

• Lists have the propertiesList-style-typeList-style-positionList-style-imageList-style

Page 68: Style Sheets

68

TablesTables

• Tables present unique difficulties for formatting purposes - are empty cells drawn?are borders separate or together?etc.

Page 69: Style Sheets

69

Creating A TableCreating A Table

table (= <TABLE>) inline-table table-row-group (= <TBODY>) table-column-group (= <COLGROUP>) table-header-group (= <THEAD>) table-footer-group (= <TFOOT>) table-column (= <COL>) table-row (= <TR>) table-cell (= <TD>) table-caption (= <CAPTION>)

Page 70: Style Sheets

70

LanguageLanguage

• :lang(x) selector - a pseudo-class that matches an element in a human language x - e.g., P:lang(en) matches <P lang="en"> (English)

• @charset - states the encoding method of the document

Page 71: Style Sheets

71

Non-left-to-right TextNon-left-to-right Text

• The direction property is used to specify the direction of text

• Direction: ltr (initial value) specifies that text goes left-to-right, and direction: rtl, right-to-left

• Unicode-bidi : specifies behavior with respect to the Unicode bidirectionality algorithm

Page 72: Style Sheets

72

Generated ContentGenerated Content

Page 73: Style Sheets

73

Generated contentGenerated content• There are three principal types of

content:non-replaced content

<P> Some non-replaced content - directly used </P>

replaced content <IMG src="green.gif"> <!-- Some replaced content - the

IMG reference is replaced by an image. -->

generated content <LI> Some non-replaced content that will be preceded by

some generated content - the list marker. </LI>

Page 74: Style Sheets

74

:Before and :after :Before and :after Pseudo-elementsPseudo-elements

• Generated content consists of putting a piece of content before or after an element

• :before and :after are used to specify where to add a generated content, e.g., P:before {content: "J”; color: red} specifies that P elements should be preceded by a (red) J

Page 75: Style Sheets

75

Counter FunctionsCounter Functions• The name of the counter function - used to

identify the counter so that references can be made to it.

• The increment of the counter - is it 1, 2, 3 or 1, 7, 13?

• The initial value of the counter - is it 1, 2, 3 or 126, 127, 128?

• The trigger to reset the counter to its initial value

• The way in which the counter is formatted - is it 1, 2, 3 or i, ii, iii?

Page 76: Style Sheets

76

CountersCounters

• Naming - P{content:counter(myCounter)}• Incrementing - H1{counter-increment:

HeadingCounter 1}• Initial values and reset - OL {counter-

reset: counter1 counter2 -26} Counter-reset only affects sibling and descendant elements

• Style - P:before {content: counter(counter, lower-alpha); counter-increment: counter}

Page 77: Style Sheets

77

CSS Formatting ModelCSS Formatting Model

The Box Model

Page 78: Style Sheets

78

CSS Formatting ModelCSS Formatting Model• CSS has a simple box-oriented formatting

model:Each HTML element is assumed to be

in a boxAll HTML elements can have box model

properties applied to them (box model properties do not inherit) margin border padding

Page 79: Style Sheets

79

The Containing BlockThe Containing Block

• All elements have a containing block• Formatted elements result in

rectangular (nested) boxes, which havecore content areaoptional surrounding padding, border and

margin areas • For example - P {margin: 10px 5px} is

applied as a 10 pixel vertical and 5 pixel horizontal margin

Page 80: Style Sheets

80

Margin and PaddingMargin and Padding

• Each element can have four margins: left, right, bottom and top

• These are defined by the margin-left, margin-right, margin-top, margin-bottom properties

• Initially margins are 0

Page 81: Style Sheets

81

Padding and BorderPadding and Border

• It is usually impossible to distinguish between padding and margin on the screen

• Padding differs from margins insofar as padding does not collapse

• Padding main importance is when an element has a rendered border

• Border is mainly important due to the width, color and style of the border

Page 82: Style Sheets

82

Dimensional Properties of BoxesDimensional Properties of Boxes

Margin (transparent)

border

Padding

Content

Element WidthBox Width

Page 83: Style Sheets

83

Positioning SchemesPositioning Schemes• Normal flow, which includes

blocks, elements, inline elements, list-items, etc.

and the positioning of these elements relative to their positions in the source file

• Floats• Absolute positioning (i.e., positioning of

content relative to a fixed point)

Page 84: Style Sheets

84

FloatsFloats

• The float property alters the normal behavior of an element

• For example, it can be used to create a drop-cap effect

• The effect of setting a float is similar to making the element part of the specified margin

• The clear property prevents an element from flowing round a floating element

Page 85: Style Sheets

85

Floats (cont’d)Floats (cont’d)

• Inline content flows around floats:<P><SPAN style="float: left; font-size: 72px; line-height: 72px; width: 50px">T</SPAN>he cat sat on the mat<BR> again <BR>once more.</P>

<P>New paragraph flows round it and continues after it.</P>---------------he cat sat on the mat | again | once more | | | New paragraph flows round itand continues after it.

Page 86: Style Sheets

86

The HTMLThe HTML

<HTML><HEAD><TITLE>Using floats</TITLE></HEAD><BODY>This is an example of using float elements:<P><STRONG>Without float:</STRONG><P><SPAN style="font-size: 100px; line-height: 90px; width:

60px">T</SPAN>he cat sat on the mat<BR> again <BR>once more. </P><P>New paragraph flows round it and continues after it.</P>

<STRONG>With float:</STRONG><P><SPAN style="float: left; font-size: 100px; line-height: 90px; width:

60px">T</SPAN>he cat sat on the mat<BR> again <BR>once more. </P><P>New paragraph flows round it and continues after it.</P></BODY></HTML>

Page 87: Style Sheets

87

Page 88: Style Sheets

88

PositioningPositioning

• An element's position is specified relative to a reference point

• In order to specify the position of elements, four properties are used: top, left, right and bottom

• The position can be static, absolute, fixed or relative

Page 89: Style Sheets

89

Positioning (cont’d)Positioning (cont’d)• Relative - the element will be relatively

positioned

• Absolute - the position of an element is specified relative to the edges of the containing block box

• Static - the element will flow normally (only static can be used for floats)

• Fixed - the element will be fixed with respect to the document window or viewport

Page 90: Style Sheets

90

EffectsEffects

Page 91: Style Sheets

91

CursorCursor• Specifies the cursor that should be

associated with the element.• Custom cursor – image is specified in

a file or a url, e.g., cursor: url(arrow.csr)• Generic cursor - auto (initial value - indicating the

value that the browser thinks is appropriate for that element) , crosshair, default (usually an arrow), pointer (cursor indicates that the item is a link), move (cursor for moving an object), text (indicates that text can be selected), wait (usually an hourglass), help (usually a ?), e-resize (cursor for resizing from the box's east corner), ne-resize, n-resize, s-resize, se-resize, w-resize, sw-resize.

Page 92: Style Sheets

92

VisibilityVisibility

• Set to visible (render the element normally)

or hidden (transparent)

• Its use is to hide content that is later shown by scripts

• E.g., P {visibility: hidden}

Page 93: Style Sheets

93

Block effectsBlock effects

• Z-index - Since elements may overlap, z-index provides for the stacking order

• A higher z-index means that an element goes further to the front

• There are two concepts:The stacking context that a box is in The stacking level for that element

Page 94: Style Sheets

94

Z-index (cont’d)Z-index (cont’d)

• Stacking contexts are stacked as a unit according to the z-index of the context

• Within a stacking context, elements are stacked in markup order

• A new stacking context is established by z-index != auto

Page 95: Style Sheets

95

Z-index ExampleZ-index Example• For example, given: <DIV style="z-index: 5; position: absolute; top: 0; left: 0">

<P style="z-index: auto; position: absolute; top: 0; left: 0"></DIV><DIV style="z-index: 4; position: absolute; top: 0; left: 0"><P style="z-index: auto; position: absolute; top: 0; left: 0"></DIV>

• The z-index: 5 places both itself and the P above the z-index 4

• For non-positioned elements, z-index is treated as auto

Page 96: Style Sheets

96

OverflowOverflow• Specifies whether content that overflows the

clipping region of a containing block should be rendered or not

• Possible treatments:scroll - using scroll barsvisible - rendering outside the clipping regionhidden - rendering only the part in the

clipping regionauto - the browser default

Page 97: Style Sheets

97

Media-dependent Style SheetsMedia-dependent Style Sheets• You specify media-dependent style sheets by adding

the media attribute to the LINK or STYLE element, e.g., <STYLE media="screen” type="text/css">

• Valid media: screen (standard computer screen), tty (fixed-pitch character grid, as with teletypes), tv projection handheld (handheld device - probably small low-resolution

screen) braille aural all (applies to all media).

Page 98: Style Sheets

98

Paged MediaPaged Media

• CSS2 provides support for paged media (e.g., printers)

• Paged media are the CSS media types of projection, handheld and embossed

• It allows setting margins, marks, naming of pages, page breaks, etc.

Page 99: Style Sheets

99

Aural Style SheetsAural Style Sheets

• Aural style sheets are vital for accessibility purposes (i.e., for blind or for people that can barely read)

• Done by specifying:Aural units, volume, speak, speech-rate,

pause-before, pause-after, pause, cue-before, cue-after, cue, play-during, azimuth, elevation, voice-family, pitch, pitch-range, stress, richness, speak-punctuation, speak-numeral

Page 100: Style Sheets

100

ConclusionConclusion

Page 101: Style Sheets

101

Advantages of CSSAdvantages of CSS

• Easy to learn• Easy to use• The core of CSS is supported by

many browsers• Can be applied to both HTML and

XML• Very flexible

Page 102: Style Sheets

102

Limitations of CSSLimitations of CSS• No transposition of elements (except for

floating)• No sibling relationship (e.g., the third

child of …), limited use of attributes (classes)

• Non-programmable:no decision structuresno extensibilityunable to store calculated quantities

Page 103: Style Sheets

103

Limitations of CSS (cont’d)Limitations of CSS (cont’d)

• No text generation• limited formatting model• Weakly supported by browsers

Page 104: Style Sheets

104

Links and ReferencesLinks and References

Page 105: Style Sheets

105

LinksLinks

• For more information on style sheets see the W3C site style sheets page

• For more information on CSS see the W3C CSS page (look at CSS1 Test Suite)

• For examples of using CSS for changing styles see the W3C CSS core styles

• W3Schools