1 5 Cascading Style Sheets CSS 2008 Pearson

  • Slides: 85
Download presentation
1 5 Cascading Style Sheets™ (CSS) 2008 Pearson Education, Inc. All rights reserved.

1 5 Cascading Style Sheets™ (CSS) 2008 Pearson Education, Inc. All rights reserved.

2 Fashions fade, style is eternal. —Yves Saint Laurent A style does not go

2 Fashions fade, style is eternal. —Yves Saint Laurent A style does not go out of style as long as it adapts itself to its period. When there is an incompatibility between the style and a certain state of mind, it is never the style that triumphs. —Coco Chanel How liberating to work in the margins, outside a central perception. —Don De. Lillo I’ve gradually risen from lower-class background to lower-class foreground. —Marvin Cohen 2008 Pearson Education, Inc. All rights reserved.

3 OBJECTIVES In this chapter you will learn: § To control the appearance of

3 OBJECTIVES In this chapter you will learn: § To control the appearance of a website by creating style sheets. § To use a style sheet to give all the pages of a website the same look and feel. § To use the class attribute to apply styles. § To specify the precise font, size, color and other properties of displayed text. § To specify element backgrounds and colors. § To understand the box model and how to control margins, borders and padding. § To use style sheets to separate presentation from content. 2008 Pearson Education, Inc. All rights reserved.

4 5. 1 Introduction 5. 2 Inline Styles 5. 3 Embedded Style Sheets 5.

4 5. 1 Introduction 5. 2 Inline Styles 5. 3 Embedded Style Sheets 5. 4 Conflicting Styles 5. 5 Linking External Style Sheets 5. 6 Positioning Elements 5. 7 Backgrounds 5. 8 Element Dimensions 5. 9 Box Model and Text Flow 5. 10 Media Types 5. 11 Building a CSS Drop-Down Menu 5. 12 User Style Sheets 5. 13 CSS 3 5. 14 Wrap-Up 5. 15 Web Resources 2008 Pearson Education, Inc. All rights reserved.

5 5. 1 Introduction • Cascading Style Sheets (CSS) allow the author of a

5 5. 1 Introduction • Cascading Style Sheets (CSS) allow the author of a web page to specify the presentation of elements separately from the structure of the document • A CSS validator is available at jigsaw. w 3. org/css-validator/ 2008 Pearson Education, Inc. All rights reserved.

6 5. 2 Inline Styles • The inline style allows you to declare a

6 5. 2 Inline Styles • The inline style allows you to declare a style for an individual element by using the style attribute in the element’s start tag • Each CSS property is followed by a colon and the value of the attribute, while multiple property declarations are separated by a semicolon 2008 Pearson Education, Inc. All rights reserved.

7 5. 2 Inline Styles (Cont. ) • The color property sets text color

7 5. 2 Inline Styles (Cont. ) • The color property sets text color – Color names and hexadecimal codes may be used as the value 2008 Pearson Education, Inc. All rights reserved.

8 Good Programming Practice 5. 1 Inline styles do not truly separate presentation from

8 Good Programming Practice 5. 1 Inline styles do not truly separate presentation from content. To apply similar styles to multiple elements, use embedded styles sheets or external style sheets, introduced later in this chapter. 2008 Pearson Education, Inc. All rights reserved.

Fig. 5. 1 | Using inline styles (Part 1 of 2). 9 Style attribute

Fig. 5. 1 | Using inline styles (Part 1 of 2). 9 Style attribute Sets the paragraph’s font size to. Sets 20 ptthe paragraph’s color to light blue 2008 Pearson Education, Inc. All rights reserved.

10 Fig. 5. 1 | Using inline styles (Part 2 of 2). 2008 Pearson

10 Fig. 5. 1 | Using inline styles (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

11 5. 3 Embedded Style Sheets • Styles that are placed in a style

11 5. 3 Embedded Style Sheets • Styles that are placed in a style element use selectors to apply style elements throughout the entire document • style element attribute type specifies the MIME type (the specific encoding format) of the style sheet. Style sheets use text/css • Each rule body in a style sheet begins and ends with a curly brace ({ and }). 2008 Pearson Education, Inc. All rights reserved.

12 5. 3 Embedded Style Sheets (Cont. ) • Style-class declarations are preceded by

12 5. 3 Embedded Style Sheets (Cont. ) • Style-class declarations are preceded by a period and are applied to elements of the specific class – The class attribute applies a style class to an element • The CSS rules in a style sheet use the same format as inline styles: – The property is followed by a colon (: ) and the value of that property – Multiple properties are separated by semicolons (; ) 2008 Pearson Education, Inc. All rights reserved.

13 5. 3 Embedded Style Sheets (Cont. ) • The font-weight property specifies the

13 5. 3 Embedded Style Sheets (Cont. ) • The font-weight property specifies the “boldness” of text. Possible values are: – – – bold normal (the default) bolder (bolder than bold text) lighter (lighter than normal text) Boldness also can be specified with multiples of 100, from 100 to 900 (e. g. , 100, 200, …, 900). Text specified as normal is equivalent to 400, and bold text is equivalent to 700 2008 Pearson Education, Inc. All rights reserved.

14 5. 3 Embedded Style Sheets (Cont. ) • The background-color attribute specifies the

14 5. 3 Embedded Style Sheets (Cont. ) • The background-color attribute specifies the background color of the element • The font-family attribute names a specific font that should be displayed – Generic font families allow authors to specify a type of font instead of a specific font, in case a browser does not support a specific font • The font-size property specifies the size used to render the font 2008 Pearson Education, Inc. All rights reserved.

15 Style sheet begins Sets the MIME type to text/css Sets the properties for

15 Style sheet begins Sets the MIME type to text/css Sets the properties for all elements in the document within em tags Sets the properties for all h 1 elements in the document Fig. 5. 2 | Embedded style sheets (Part 1 of 2). Sets the properties for all p elements in the document Creates a special class Style sheet ends 2008 Pearson Education, Inc. All rights reserved.

16 Fig. 5. 2 | Embedded The special class style is sheets applied to

16 Fig. 5. 2 | Embedded The special class style is sheets applied to this p element (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

17 5. 4 Conflicting Styles • Styles defined by the user take precedence over

17 5. 4 Conflicting Styles • Styles defined by the user take precedence over styles defined by the user agent, and styles defined by authors take precedence over styles defined by the user • Most styles are inherited from parent elements. Styles defined for children have higher specificity and take precedence over the parent’s styles • Conflicts are resolved in favor of properties with a higher specificity 2008 Pearson Education, Inc. All rights reserved.

18 5. 4 Conflicting Styles (Cont. ) • The text-decoration property applies decorations to

18 5. 4 Conflicting Styles (Cont. ) • The text-decoration property applies decorations to text in an element, such as underline, overline, line-through and blink 2008 Pearson Education, Inc. All rights reserved.

19 5. 4 Conflicting Styles (Cont. ) • Pseudoclasses give the author access to

19 5. 4 Conflicting Styles (Cont. ) • Pseudoclasses give the author access to content not specifically declared in the document • Pseudoclasses are separated by a colon (with no surrounding spaces) from the name of the element to which they are applied • The hover pseudoclass is activated when the user moves the mouse cursor over an element 2008 Pearson Education, Inc. All rights reserved.

20 5. 4 Conflicting Styles (Cont. ) • To apply rules to multiple elements,

20 5. 4 Conflicting Styles (Cont. ) • To apply rules to multiple elements, separate the elements with commas in the style sheet • To apply rules to only a certain type of element that is a child of another type, separate the element names with spaces 2008 Pearson Education, Inc. All rights reserved.

21 5. 4 Conflicting Styles (Cont. ) • Relative length measurements: – – px

21 5. 4 Conflicting Styles (Cont. ) • Relative length measurements: – – px (pixels – size varies depending on screen resolution) em (usually the height of a font’s uppercase M) ex (usually the height of a font’s lowercase x) Percentages (of the font’s default size) • Absolute-length measurements (units that do not vary in size): – – – in (inches) cm (centimeters) mm (millimeters) pt (points; 1 pt = 1/72 in) pc (picas; 1 pc = 12 pt) 2008 Pearson Education, Inc. All rights reserved.

22 Defines the class nodec that can only be used by anchor elements Fig.

22 Defines the class nodec that can only be used by anchor elements Fig. 5. 3 | Inheritance in style sheets (Part 1 of 3). Sets the properties for the hover pseudoclass for the a element, which is activated when the user moves the cursor over an anchor element All em elements that are children of li elements set to bold Applies underline style to all h 1 and em elements 2008 Pearson Education, Inc. All rights reserved.

23 Fig. 5. 3 | Inheritance in style sheets (Part 2 of 3). 2008

23 Fig. 5. 3 | Inheritance in style sheets (Part 2 of 3). 2008 Pearson Education, Inc. All rights reserved.

24 Fig. 5. 3 | Inheritance in style sheets (Part 3 of 3). 2008

24 Fig. 5. 3 | Inheritance in style sheets (Part 3 of 3). 2008 Pearson Education, Inc. All rights reserved.

25 Portability Tip 5. 1 To ensure that your style sheets work in various

25 Portability Tip 5. 1 To ensure that your style sheets work in various web browsers, test them on all the client web browsers that will render documents using your styles, as well as using the W 3 C CSS Validator. 2008 Pearson Education, Inc. All rights reserved.

26 Common Programming Error 5. 1 Including a space before or after the colon

26 Common Programming Error 5. 1 Including a space before or after the colon separating a pseudoclass from the name of the element to which it is applied is an error that prevents the pseudoclass from being applied properly. 2008 Pearson Education, Inc. All rights reserved.

27 Good Programming Practice 5. 2 Whenever possible, use relative-length measurements. If you use

27 Good Programming Practice 5. 2 Whenever possible, use relative-length measurements. If you use absolute-length measurements, your document may not be readable on some client browsers (e. g. , wireless phones). 2008 Pearson Education, Inc. All rights reserved.

28 5. 5 Linking External Style Sheets • External style sheets are separate documents

28 5. 5 Linking External Style Sheets • External style sheets are separate documents that contain only CSS rules • External linking of style sheets can create a uniform look for a website, since separate pages can all use the same styles • Modifying a single style-sheet file makes changes to styles across an entire website 2008 Pearson Education, Inc. All rights reserved.

29 Software Engineering Observation 5. 1 Always use an external style sheet when developing

29 Software Engineering Observation 5. 1 Always use an external style sheet when developing a website with multiple pages. External style sheets separate content from presentation, allowing for more consistent look-and-feel, more efficient development, and better performance. 2008 Pearson Education, Inc. All rights reserved.

30 5. 5 Linking External Style Sheets (Cont. ) • The link element in

30 5. 5 Linking External Style Sheets (Cont. ) • The link element in an XHTML document uses the rel attribute to specify a relationship between two documents – The rel attribute declares the linked document to be a stylesheet for the document • The type attribute specifies the MIME type of the related document • The href attribute provides the URL for the document containing the style sheet 2008 Pearson Education, Inc. All rights reserved.

31 Fig. 5. 4 | External style sheet. 2008 Pearson Education, Inc. All rights

31 Fig. 5. 4 | External style sheet. 2008 Pearson Education, Inc. All rights reserved.

32 Fig. 5. 5 | Linking an external style sheet (Part 1 of 2).

32 Fig. 5. 5 | Linking an external style sheet (Part 1 of 2). The linked document is declared to be the current one’s stylesheet The linked document’s MIME type is text/css The linked document’s URL is styles. css 2008 Pearson Education, Inc. All rights reserved.

33 Fig. 5. 5 | Linking an external style sheet (Part 2 of 2).

33 Fig. 5. 5 | Linking an external style sheet (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

34 Software Engineering Observation 5. 2 External style sheets are reusable. Creating them once

34 Software Engineering Observation 5. 2 External style sheets are reusable. Creating them once and reusing them reduces programming effort. 2008 Pearson Education, Inc. All rights reserved.

35 Performance Tip 5. 1 Reusing external style sheets reduces load time and bandwidth

35 Performance Tip 5. 1 Reusing external style sheets reduces load time and bandwidth usage on a server, since the style sheet can be downloaded once, stored by the web browser, and applied to all pages on a website. 2008 Pearson Education, Inc. All rights reserved.

36 5. 6 Positioning Elements • The CSS position property allows absolute positioning, which

36 5. 6 Positioning Elements • The CSS position property allows absolute positioning, which provides greater control over where on a page elements reside – Normally, elements are positioned on the page in the order that they appear in the XHTML document • Specifying an element’s position as absolute removes it from the normal flow of elements on the page and positions it according to distance from the top, left, right or bottom margin of its parent element 2008 Pearson Education, Inc. All rights reserved.

37 5. 6 Positioning Elements (Cont. ) • The z-index property allows a developer

37 5. 6 Positioning Elements (Cont. ) • The z-index property allows a developer to layer overlapping elements • Elements that have higher z-index values are displayed in front of elements with lower z-index values 2008 Pearson Education, Inc. All rights reserved.

38 Class that sets an element’s absolute position at the top left of the

38 Class that sets an element’s absolute position at the top left of the containing element Fig. 5. 6 | Absolute positioning of elements (Part 1 of 2). Lowest z-index, so this element is behind all the others Set element’s position 25 px from the top and 100 from the left This element will appear on top of the first one, since it has a higher z-index This element will appear on top of all others, since it has the highest z-index 2008 Pearson Education, Inc. All rights reserved.

39 Fig. 5. 6 | Absolute positioning of elements (Part 2 of 2). 2008

39 Fig. 5. 6 | Absolute positioning of elements (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

40 5. 6 Positioning Elements (Cont. ) • Relative positioning keeps elements in the

40 5. 6 Positioning Elements (Cont. ) • Relative positioning keeps elements in the general flow on the page and offsets them by the specified top, left, right or bottom value 2008 Pearson Education, Inc. All rights reserved.

41 5. 6 Positioning Elements (Cont. ) • Inline-level elements – Do not change

41 5. 6 Positioning Elements (Cont. ) • Inline-level elements – Do not change the flow of the document – Examples: • img • a • em • strong • span – Grouping element – Does not apply any formatting to its contents – Creates a container for CSS rules or id attributes to be applied to a section 2008 Pearson Education, Inc. All rights reserved.

42 5. 6 Positioning Elements (Cont. ) • Block-level elements – Displayed on their

42 5. 6 Positioning Elements (Cont. ) • Block-level elements – Displayed on their own line – Have virtual boxes around them – Examples: • p • all headings (h 1 through h 6) • div – A grouping element like span 2008 Pearson Education, Inc. All rights reserved.

43 Fig. 5. 7 | Relative positioning of elements (Part 1 of 2). Positions

43 Fig. 5. 7 | Relative positioning of elements (Part 1 of 2). Positions element 5 ex upwards Positions element 1 ex downwards Positions element 1 ex to the left Positions element 1 ex to the right Apply the super class to this span element 2008 Pearson Education, Inc. All rights reserved.

44 Apply the sub class to this span element Fig. 5. 7 | Relative

44 Apply the sub class to this span element Fig. 5. 7 | Relative Apply the shiftleft class to this span element positioning of elements Apply the shiftright (Part 2 of 2). class to this span element 2008 Pearson Education, Inc. All rights reserved.

45 Common Programming Error 5. 2 Because relative positioning keeps elements in the flow

45 Common Programming Error 5. 2 Because relative positioning keeps elements in the flow of text in your documents, be careful to avoid unintentionally overlapping text. 2008 Pearson Education, Inc. All rights reserved.

46 5. 7 Backgrounds • CSS can control the backgrounds of block-level elements by

46 5. 7 Backgrounds • CSS can control the backgrounds of block-level elements by adding: – Colors – Images 2008 Pearson Education, Inc. All rights reserved.

47 5. 7 Backgrounds (Cont. ) • Property background-image specifies the URL of the

47 5. 7 Backgrounds (Cont. ) • Property background-image specifies the URL of the image, in the format url(file. Location) • The property background-position places the image on the page using the values top, bottom, center, left and right individually or in combination for vertical and horizontal positioning. You can also position by using lengths 2008 Pearson Education, Inc. All rights reserved.

48 5. 7 Backgrounds (Cont. ) • Property background-image specifies the URL of the

48 5. 7 Backgrounds (Cont. ) • Property background-image specifies the URL of the image – Use the format url(file. Location) • The property background-position places the image on the page – Use the values top, bottom, center, left and right individually or in combination for vertical and horizontal positioning – You can also position by specifying horizontal then vertical distances from the top-left corner of the screen 2008 Pearson Education, Inc. All rights reserved.

49 5. 7 Backgrounds (Cont. ) • The background-repeat property controls the tiling of

49 5. 7 Backgrounds (Cont. ) • The background-repeat property controls the tiling of the background image – Setting the tiling to no-repeat displays one copy of the background image on screen – Setting to repeat (the default) tiles the image vertically and horizontally – Setting to repeat-x tiles the image only horizontally – Setting to repeat-y tile the image only vertically 2008 Pearson Education, Inc. All rights reserved.

50 5. 7 Backgrounds (Cont. ) • The property setting backgroundattachment: fixed fixes the

50 5. 7 Backgrounds (Cont. ) • The property setting backgroundattachment: fixed fixes the image in the position specified by background-position. Scrolling the browser window will not move the image from its set position. The default value, scroll, moves the image as the user scrolls the window 2008 Pearson Education, Inc. All rights reserved.

51 5. 7 Backgrounds (Cont. ) • The text-indent property indents the first line

51 5. 7 Backgrounds (Cont. ) • The text-indent property indents the first line of text in the element by the specified amount • The font-style property allows you to set text to none, italic or oblique 2008 Pearson Education, Inc. All rights reserved.

52 Inserts the image at logo. gif as the background Fig. 5. 8 |

52 Inserts the image at logo. gif as the background Fig. 5. 8 | Adding background Places the image at the bottom images and right of the page indentation (Part 1 of 2). Displays only one copy of the image Keeps the image in place when the user scrolls in the browser window Fills the remainder of the window with a light gray background Indents the first line of text in the element by 1 em 2008 Pearson Education, Inc. All rights reserved.

53 Fig. 5. 8 | Adding background images and indentation (Part 2 of 2).

53 Fig. 5. 8 | Adding background images and indentation (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

54 5. 8 Element Dimensions • The dimensions of elements on a page can

54 5. 8 Element Dimensions • The dimensions of elements on a page can be set with CSS by using properties height and width – Their values can be relative or absolute • Text in an element can be centered using textalign: center; other values for the text-align property are left and right 2008 Pearson Education, Inc. All rights reserved.

55 5. 8 Element Dimensions (Cont. ) • The dimensions of elements on a

55 5. 8 Element Dimensions (Cont. ) • The dimensions of elements on a page can be set with CSS by using properties height and width – Their values can be relative or absolute • One problem with setting both vertical and horizontal dimensions of an element is that the content might sometimes exceed the set boundaries, in which case the element must be made large enough for all the content to fit. However, a developer can set the overflow property to scroll, which adds scroll bars if the text overflows the boundaries set for it 2008 Pearson Education, Inc. All rights reserved.

56 Fig. 5. 9 | Element dimensions and text alignment (Part 1 of 2).

56 Fig. 5. 9 | Element dimensions and text alignment (Part 1 of 2). Sets the width of the element to 20% of the browser’s screen’s size Sets the width of the element to 80% of the browser’s screen’s size and centers it 2008 Pearson Education, Inc. All rights reserved.

57 Sets the width of the element to 20% of the browser’s screen’s size,

57 Sets the width of the element to 20% of the browser’s screen’s size, the height to 150 px, and allows the element to scroll if the text overflows the allotted size Fig. 5. 9 | Element dimensions and text alignment (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

58 5. 9 Box Model and Text Flow • Block-level XHTML elements have a

58 5. 9 Box Model and Text Flow • Block-level XHTML elements have a virtual box drawn around them based on the box model • When the browser renders using the box model, each element is surrounded by: – Padding • The padding property determines the distance between the content inside an element and the edge of the element • Padding be set for each side of the box by using padding-top, paddingright, padding-left and padding-bottom – A margin • Determines the distance between the element’s edge and any outside text • Margins for individual sides of an element can be specified by using margin -top, margin-right, margin-left and margin-bottom – A border 2008 Pearson Education, Inc. All rights reserved.

59 5. 9 Box Model and Text Flow (Cont. ) • The border is

59 5. 9 Box Model and Text Flow (Cont. ) • The border is controlled using the properties: – border-width • May be set to any of the CSS lengths or to the predefined value of thin, medium or thick – border-color • Sets the color used for the border – border-style • Options are: none, hidden, dotted, dashed, solid, double, groove, ridge, inset and outset 2008 Pearson Education, Inc. All rights reserved.

60 5. 9 Box Model and Text Flow (Cont. ) • The class attribute

60 5. 9 Box Model and Text Flow (Cont. ) • The class attribute allows more than one class to be assigned to an XHTML element by separating each class name from the next with a space 2008 Pearson Education, Inc. All rights reserved.

61 Fig. 5. 10 | Box model for block-level elements. 2008 Pearson Education, Inc.

61 Fig. 5. 10 | Box model for block-level elements. 2008 Pearson Education, Inc. All rights reserved.

62 Fig. 5. 11 | Borders of block-level elements (Part 1 of 2). Defines

62 Fig. 5. 11 | Borders of block-level elements (Part 1 of 2). Defines several border classes 2008 Pearson Education, Inc. All rights reserved.

Applies several classes to the same element 63 Fig. 5. 11 | Borders of

Applies several classes to the same element 63 Fig. 5. 11 | Borders of block-level elements (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

64 5. 9 Box Model and Text Flow (Cont. ) • Browsers normally place

64 5. 9 Box Model and Text Flow (Cont. ) • Browsers normally place text and elements on screen in the order in which they appear in the XHTML file. Elements can be removed from the normal flow of text. Floating allows you to move an element to one side of the screen; other content in the document will then flow around the floated element 2008 Pearson Education, Inc. All rights reserved.

65 Fig. 5. 12 | Floating elements (Part 1 of 3). Sets a spacing

65 Fig. 5. 12 | Floating elements (Part 1 of 3). Sets a spacing of. 5 em from the outside of the border to all other content Sets a spacing of. 2 em from the inside of the border to the element’s content Define left and right margins Moves element to the right, and lets other content flow around it Defines the border for this div class 2008 Pearson Education, Inc. All rights reserved.

66 Fig. 5. 12 | Floating elements (Part 2 of 3). 2008 Pearson Education,

66 Fig. 5. 12 | Floating elements (Part 2 of 3). 2008 Pearson Education, Inc. All rights reserved.

67 Fig. 5. 12 | Floating elements (Part 3 of 3). 2008 Pearson Education,

67 Fig. 5. 12 | Floating elements (Part 3 of 3). 2008 Pearson Education, Inc. All rights reserved.

68 5. 10 Media Types • CSS media types allow a programmer to decide

68 5. 10 Media Types • CSS media types allow a programmer to decide what a page should look like depending on the kind of media being used to display the page • The most common media type for a web page is the screen media type, which is a standard computer screen 2008 Pearson Education, Inc. All rights reserved.

69 5. 10 Media Types (Cont. ) • A block of styles that applies

69 5. 10 Media Types (Cont. ) • A block of styles that applies to all media types is declared by @media all and enclosed in curly braces • To create a block of styles that apply to a single media type such as print, use @media print and enclose the style rules in curly braces 2008 Pearson Education, Inc. All rights reserved.

70 5. 10 Media Types (Cont. ) • Other media types in CSS 2

70 5. 10 Media Types (Cont. ) • Other media types in CSS 2 include: – handheld • Designed for mobile Internet devices – braille • For machines that can read or print web pages in braille – aural • Allow the programmer to give a speech-synthesizing web browser more information about the content of the web page – print • Affects a web page’s appearance when it is printed 2008 Pearson Education, Inc. All rights reserved.

71 Fig. 5. 13 | CSS media types (Part 1 Sets properties for all

71 Fig. 5. 13 | CSS media types (Part 1 Sets properties for all media of 2). types Sets properties for a page if it is being printed 2008 Pearson Education, Inc. All rights reserved.

72 Fig. 5. 13 | CSS media types (Part 2 of 2). 2008 Pearson

72 Fig. 5. 13 | CSS media types (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

73 Look-and-Feel Observation 5. 1 Pages with dark background colors and light text use

73 Look-and-Feel Observation 5. 1 Pages with dark background colors and light text use a lot of ink and may be difficult to read when printed, especially on a black-and white-printer. Use the print media type to avoid this. 2008 Pearson Education, Inc. All rights reserved.

74 Look-and-Feel Observation 5. 2 In general, sans-serif fonts look better on a screen,

74 Look-and-Feel Observation 5. 2 In general, sans-serif fonts look better on a screen, while serif fonts look better on paper. The print media type allows your web page to display sans-serif font on a screen and change to a serif font when it is printed. 2008 Pearson Education, Inc. All rights reserved.

75 5. 11 Building a CSS Drop-Down Menu • The : hover pseudoclass is

75 5. 11 Building a CSS Drop-Down Menu • The : hover pseudoclass is used to apply styles to an element when the mouse cursor is over it • The display property allows a programmer to decide if an element is displayed as a block element, inline element, or is not rendered at all (none) 2008 Pearson Education, Inc. All rights reserved.

76 Fig. 5. 14 | CSS dropdown menu (Part 1 of 2). Sets anchor

76 Fig. 5. 14 | CSS dropdown menu (Part 1 of 2). Sets anchor elements in a menu div to be displayed as block-level when the menu is moused-over Prevents the browser from rendering the links inside the menu div Sets anchor elements in a menu div to have a lightblue background when they are moused-over 2008 Pearson Education, Inc. All rights reserved.

77 Fig. 5. 14 | CSS dropdown menu (Part 2 of 2). 2008 Pearson

77 Fig. 5. 14 | CSS dropdown menu (Part 2 of 2). 2008 Pearson Education, Inc. All rights reserved.

78 5. 12 User Style Sheets • Users can define their own user style

78 5. 12 User Style Sheets • Users can define their own user style sheets to format pages based on their preferences • Absolute font size measurements override user style sheets, while relative font sizes will yield to a user-defined style • User style sheets are not linked to a document; rather, they are set in the browser’s options 2008 Pearson Education, Inc. All rights reserved.

79 Fig. 5. 15 | pt measurement for text size. A class defined by

79 Fig. 5. 15 | pt measurement for text size. A class defined by the author with absolute measurements: a font-size of 9 pt 2008 Pearson Education, Inc. All rights reserved.

80 A different font-size of 20 pt is defined by the user for all

80 A different font-size of 20 pt is defined by the user for all body elements Fig. 5. 16 | User style sheet. 2008 Pearson Education, Inc. All rights reserved.

81 Fig. 5. 17 | User style sheet in Internet Explorer 7. 2008 Pearson

81 Fig. 5. 17 | User style sheet in Internet Explorer 7. 2008 Pearson Education, Inc. All rights reserved.

82 The author’s style has higher precedence than the user’s, so the font is

82 The author’s style has higher precedence than the user’s, so the font is 9 pt Fig. 5. 18 | User style sheet applied with pt measurement. 2008 Pearson Education, Inc. All rights reserved.

83 Fig. 5. 19 | em measurement for text size. A relative measurement of.

83 Fig. 5. 19 | em measurement for text size. A relative measurement of. 75 em is used by the author for the font size 2008 Pearson Education, Inc. All rights reserved.

84 The user style sheet is considered, so the font-size is 15 pt (.

84 The user style sheet is considered, so the font-size is 15 pt (. 75 em for 20 pt) Fig. 5. 20 | User style sheet applied with em measurement. 2008 Pearson Education, Inc. All rights reserved.

85 5. 13 CSS 3 • While CSS 2 is the current W 3

85 5. 13 CSS 3 • While CSS 2 is the current W 3 C Recommendation, CSS 3 is in development, and some browsers are beginning to implement some of the new features that will be in the CSS 3 specification • CSS 3 will introduce new features related to borders, backgrounds, text effects, layout, and more 2008 Pearson Education, Inc. All rights reserved.