+ All Categories
Home > Documents > CHAPTER 2

CHAPTER 2

Date post: 22-Feb-2016
Category:
Upload: dai
View: 51 times
Download: 0 times
Share this document with a friend
Description:
CHAPTER 2. CSS (Cascading Style Sheet). Topics. Introduction Inline Styles Embedded Style Sheets Conflicting Styles Linking External Style Sheets Positioning Elements Backgrounds Element Dimensions Text Flow and the Box Model User Style Sheets. Learning Outcomes. - PowerPoint PPT Presentation
Popular Tags:
84
CHAPTER 2 CSS (Cascading Style Sheet)
Transcript
Page 1: CHAPTER 2

CHAPTER 2CSS

(Cascading Style Sheet)

Page 2: CHAPTER 2

Topics

• Introduction• Inline Styles• Embedded Style Sheets• Conflicting Styles• Linking External Style Sheets• Positioning Elements• Backgrounds• Element Dimensions• Text Flow and the Box Model• User Style Sheets

Page 3: CHAPTER 2

Learning Outcomes

At the end of this lesson, students should be able to:

– Control the appearance of a Web site by creating style sheets.– Use a style sheet to give all the pages of a Web site the same

look and feel.– Use the class attribute to apply styles. – Specify the precise font, size, color and other properties of

displayed text. – Specify element backgrounds and colors.– Understand the box model and how to control the margins,

borders and padding.– Use style sheets to separate presentation from content.

Page 4: CHAPTER 2

Introduction

• Cascading Style Sheets (CSS)– Separation of structure from presentation– new way of formatting your page layout, text, fonts,

images– allow you to position things on your page down to the

exact pixel– style sheets types:

• Inline style sheet • Embedded or Internal style sheet • External style sheet

Page 5: CHAPTER 2

Inline Styles

• An inline style loses many of the advantages of style sheets by mixing content with presentation.

• Therefore, you should use this method sparingly, such as when a style is to be applied to a single occurrence of an element

• Declare an individual element’s format– Attribute style– CSS property

• Followed by a colon and a value

Page 6: CHAPTER 2

inline.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.1: inline.html --> 6 <!-- Using inline styles --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Inline Styles</title> 11 </head> 12 13 <body> 14 15 <p>This text does not have any style applied to it.</p> 16 17 <!-- The style attribute allows you to declare --> 18 <!-- inline styles. Separate multiple styles --> 19 <!-- with a semicolon. --> 20 <p style = "font-size: 20pt">This text has the 21 <em>font-size</em> style applied to it, making it 20pt. 22 </p> 23

Page 7: CHAPTER 2

inline.html(2 of 2)

24 <p style = "font-size: 20pt; color: #0000ff"> 25 This text has the <em>font-size</em> and 26 <em>color</em> styles applied to it, making it 27 20pt. and blue.</p> 28 29 </body> 30 </html>

Page 8: CHAPTER 2

Embedded/Internal Style Sheets

• An internal style sheet should be used when a single document has a unique style.

• Embed an entire CSS document in an HTML document’s head section– Property background-color

• Specifies the background color– font-family(line 18)-specifies the name of font

to use.h1 { font-family: arial, sans-serif }

Page 9: CHAPTER 2

Embedded/Internal Style Sheets

• Font arial will be used. If the arial font is not found on the system, the browser instead will display a generic sans-serif font.

• Other generic font families: – Serif (e.g:Times New Roman, Georgia)– Sans-Serif (e.g: Helvetica, Verdana)– Cursive ( e.g: script)– Fantasy (e.g: critter)– Monospace (e.g: Courier, Fixedsys)

• font-size(line 20)-specifies the size of font.

Page 10: CHAPTER 2

Embedded/Internal Style Sheets

• Other possible measurements in addition to pt(point)- will be introduced later.

• Relative values- xx-small, x-small, small, smaller, medium, large, larger, x-large and xx-large.

Page 11: CHAPTER 2

Embedded/Internal Style Sheets

• Relative values are preferred because an author does not know the specific measurements of the display for each client.

• Relative font-size values permit more flexible viewing of web pages.

• If relative font-size is specified, the actual size is determined by the browser that displays the font.

• E.g: Handheld device with a small screen.

Page 12: CHAPTER 2

Embedded/Internal Style Sheets

12

Dreamweaver environment

Page 13: CHAPTER 2

declared.html(1 of 3)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.2: declared.html --> 6 <!-- Declaring a style sheet in the header section. --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Style Sheets</title> 11 12 <!-- this begins the style sheet section --> 13 <style type = "text/css"> 14 15 em { background-color: #8000ff; 16 color: white } 17 18 h1 { font-family: arial, sans-serif } 19 20 p { font-size: 14pt } 21 22 .special { color: blue } 23 24 </style> 25 </head>

Page 14: CHAPTER 2

declared.html(2 of 3)

26 27 <body> 28 29 <!-- this class attribute applies the .special style --> 30 <h1 class = "special">Deitel & Associates, Inc.</h1> 31 32 <p>Deitel &amp; Associates, Inc. is an internationally 33 recognized corporate training and publishing organization 34 specializing in programming languages, Internet/World 35 Wide Web technology and object technology education. 36 Deitel &amp; Associates, Inc. is a member of the World Wide 37 Web Consortium. The company provides courses on Java, 38 C++, Visual Basic, C, Internet and World Wide Web 39 programming, and Object Technology.</p> 40 41 <h1>Clients</h1> 42 <p class = "special"> The company's clients include many 43 <em>Fortune 1000 companies</em>, government agencies, 44 branches of the military and business organizations. 45 Through its publishing partnership with Prentice Hall, 46 Deitel &amp; Associates, Inc. publishes leading-edge 47 programming textbooks, professional books, interactive 48 CD-ROM-based multimedia Cyber Classrooms, satellite 49 courses and World Wide Web courses.</p> 50

Page 15: CHAPTER 2

declared.html(3 of 3)

51 </body> 52 </html>

Page 16: CHAPTER 2

Embedded/Internal Style Sheets

16

Dreamweaver environment

Page 17: CHAPTER 2

Selector forms

Simple Selector Forms•The simplest selector form is a single element name, such as h1.•Consider the following examples:

h1 {font-size: 20pt;}h2, h3 {font-size: 20pt;}form em {font-size: 20pt;}

17

Page 18: CHAPTER 2

Selector forms

Class Selectors•Class selectors are used to allow different occurrences of the same tag to use different style specifications.•Consider the following examples:

18

Page 19: CHAPTER 2

Selector forms

p.normal {font-size: 20pt;}p.warning {font-size: 6pt;}

19

<p class= “normal”>……………………………</p><p class= “warning”>……………………………</p>

Page 20: CHAPTER 2

Selector forms

Generic Selectors•A class of style specifications that applies to the content of more than one kind of tag.

20

Page 21: CHAPTER 2

Selector forms

.sale {font-size: 20pt;}

21

<p class= “sale”>……………………………</p><h2 class= “sale”>……………………………</p>

Page 22: CHAPTER 2

Conflicting Styles

• InheritanceHTML<p class = "special"> The company's clients includemany <em>Fortune 1000 companies</em>, government agencies………..</p>CSSem { background-color: #8000ff; color: white } p { font-size: 14pt }

.special { color: blue } – Child em element inherited the font-size property

from its parent p element.– However, the child em element had a color

property that conflicted with the color property of its parent p element.

Page 23: CHAPTER 2

Conflicting Styles

• Descendant’s properties have greater specificity than ancestor’s properties.

• Conflicts are resolved in favor of properties with a higher specificity.

• em will be white in color instead of blue.

Page 24: CHAPTER 2

Conflicting Styles

<html> <head> <style type="text/css"> .navtext {color: black; font-weight: bold} p {color: blue} </style> </head> <body> <p class="navtext" style="color: red">Link 1</p> <p class="navtext">Link 2</p> <p>Link 3</p> </body></html> 24

Page 25: CHAPTER 2

advance.html(1 of 3)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig 6.3: advanced.html --> 6 <!-- More advanced style sheets --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>More Styles</title> 11 12 <style type = "text/css"> 13 14 a.nodec { text-decoration: none } 15 16 a:hover { text-decoration: underline; 17 color: red; 18 background-color: #ccffcc } 19 20 li em { color: red; 21 font-weight: bold } 22 23 ul { margin-left: 75px } 24

Page 26: CHAPTER 2

advance.html(2 of 3)

25 ul ul { text-decoration: underline; 26 margin-left: 15px } 27 28 </style> 29 </head> 30 31 <body> 32 33 <h1>Shopping list for <em>Monday</em>:</h1> 34 35 <ul> 36 <li>Milk</li> 37 <li>Bread 38 <ul> 39 <li>White bread</li> 40 <li>Rye bread</li> 41 <li>Whole wheat bread</li> 42 </ul> 43 </li> 44 <li>Rice</li> 45 <li>Potatoes</li> 46 <li>Pizza <em>with mushrooms</em></li> 47 </ul> 48

Page 27: CHAPTER 2

advance.html(3 of 3)

49 <p><a class = "nodec" href = "http://www.food.com"> 50 Go to the Grocery store</a></p> 51 52 </body> 53 </html>

Page 28: CHAPTER 2

Linking External Style Sheets

• External style sheets– External style sheets are the best method when you

want the style to be applied to many pages. – With an external style sheet, you can change the look

of an entire web site by changing one external style sheet file.

– Text-decoration applies decorations to text within an element.

– Possible values of Text-decoration – none, overline, line-through, underline, blink(not supported by IE)

Page 29: CHAPTER 2

Linking External Style Sheets

– hover (pseudoclass)(line 16-18)- activated dynamically when the user moves the mouse cursor over an element.

– Pseudoclassses are separated by a colon from the name of the element to which they are applied.

Page 30: CHAPTER 2

Linking External Style Sheets

• Margin-left(line 23 & 26)- ul { margin-left: 15px }

• Left-hand margin of 15 pixels• Relative-length measurement- varies in size,

based on screen resolution. Example: px, em, ex, percentage(%)

• Absolute-length measurement- not vary in size based on the system. Example: in(inches), cm(centimeter), mm(milimeter), pt(points; 1pt= 1/72 in), pc(picas; 1pc= 12 pt)

Page 31: CHAPTER 2

Linking External Style Sheets

31

Dreamweaver environment

Page 32: CHAPTER 2

styles.css(1 of 1)

1 /* Fig. 6.4: styles.css */ 2 /* An external stylesheet */ 3 4 a { text-decoration: none } 5 6 a:hover { text-decoration: underline; 7 color: red; 8 background-color: #ccffcc } 9 10 li em { color: red; 11 font-weight: bold; 12 background-color: #ffffff } 13 14 ul { margin-left: 2cm } 15 16 ul ul { text-decoration: underline; 17 margin-left: .5cm }

Page 33: CHAPTER 2

external.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.5: external.html --> 6 <!-- Linking external style sheets --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Linking External Style Sheets</title> 11 <link rel = "stylesheet" type = "text/css" 12 href = "styles.css" /> 13 </head> 14 15 <body> 16 17 <h1>Shopping list for <em>Monday</em>:</h1> 18 <ul> 19 <li>Milk</li> 20 <li>Bread 21 <ul> 22 <li>White bread</li> 23 <li>Rye bread</li> 24 <li>Whole wheat bread</li> 25 </ul>

Page 34: CHAPTER 2

external.html(2 of 2)

26 </li> 27 <li>Rice</li> 28 <li>Potatoes</li> 29 <li>Pizza <em>with mushrooms</em></li> 30 </ul> 31 32 <p> 33 <a href = "http://www.food.com">Go to the Grocery store</a> 34 </p> 35 36 </body> 37 </html>

Page 35: CHAPTER 2

Properties & Property Values

• There are a large number of CSS properties that you can use with HTML.

• It is impossible for us to cover all the properties in this course.

• At the end of this slide, there are a number of references provided for you to refer.

35

Page 36: CHAPTER 2

List: Property & Property Values

<h3> Some Common Single-Engine Aircraft </h3> <ul style = "list-style-type: square"> <li> Cessna Skyhawk </li> <li> Beechcraft Bonanza </li> <li> Piper Cherokee </li> </ul><h3> Some Common Single-Engine Aircraft </h3> <ul> <li style = "list-style-type: disc"> Cessna Skyhawk </li> <li style = "list-style-type: square"> Beechcraft Bonanza </li> <li style = "list-style-type: circle"> Piper Cherokee </li> </ul>

36

Page 37: CHAPTER 2

List: Property & Property Values

• Other list-style-type values:

Property value First four

decimal 1, 2, 3, 4 upper-alpha A, B, C, D lower-alpha a, b, c, d upper-roman I, II, III, IV lower-roman i, ii, iii, iv

37

Page 38: CHAPTER 2

Positioning Elements

• Absolute positioning– Removes the elements from the normal

flow of elements on the page, instead positioning it according to the distance from the top, left, right, or bottom margin of its containing block-level element (i.e: body, p)

– z-index attribute• Layer overlapping elements properly

Page 39: CHAPTER 2

Positioning Elements

– Elements that have a higher z-index values are displayed in front of elements with lower z-index values.

– If z-index is not specified or elements have same z-index value

• Elements are placed from background to foreground in order they are encountered in the document.

• Relative positioning– Elements are positioned relative to other

elements

Page 40: CHAPTER 2

positioning.html(1 of 1)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig 6.8: positioning.html --> 6 <!-- Absolute positioning of elements --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Absolute Positioning</title> 11 </head> 12 13 <body> 14 15 <p><img src = "i.gif" style = "position: absolute; 16 top: 0px; left: 0px; z-index: 1" 17 alt = "First positioned image" /></p> 18 <p style = "position: absolute; top: 50px; left: 50px; 19 z-index: 3; font-size: 20pt">Positioned Text</p> 20 <p><img src = "circle.gif" style = "position: absolute; 21 top: 25px; left: 100px; z-index: 2" alt = 22 "Second positioned image" /></p> 23 24 </body> 25 </html>

Page 41: CHAPTER 2
Page 42: CHAPTER 2

Positioning Elements

42

Dreamweaver environment

Page 43: CHAPTER 2

Positioning Elements

43

Dreamweaver environment

Page 44: CHAPTER 2

span

• One problem with the font properties is that they apply to whole elements, which are often too large

• Solution: a new tag to define an element in the content of a larger element - <span>

• The default meaning of <span> is to leave the content as it is

44

Page 45: CHAPTER 2

span

• Example: <p> Now is the <span> best time </span> ever! </p>

• Use <span> to apply an inline style sheet to its content

<p> Now is the <span style = "font-size: 40; font-family: Arial; color: red"> best time </span> ever! </p>

Page 46: CHAPTER 2

Span & div

• The <span> tag is similar to other HTML tags, they can be nested and they have id and class attributes

• Another tag that is useful for style specifications:<div>

• Used to create document sections (or divisions) for which style can be specifiede.g.: A section of five paragraphs for which you want some particular style

Page 47: CHAPTER 2

Span & div

<html> <head> <style type="text/css"> .try {font-size:6pt}; .try1 {font-size:50pt}; </style> </head> <body> <div class="try"> <p> A </p> <p> A </p> <p> A </p> <p> A </p> <p> A </p> <p> A </p> </div> <p>Hello <span class="try1">Welcome </span>to Web Programming </p> </body> </html>

47

Page 48: CHAPTER 2

positioning2.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.9: positioning2.html --> 6 <!-- Relative positioning of elements --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Relative Positioning</title> 11 12 <style type = "text/css"> 13 14 p { font-size: 1.3em; 15 font-family: verdana, arial, sans-serif } 16 17 span { color: red; 18 font-size: .6em; 19 height: 1em } 20 21 .super { position: relative; 22 top: -1ex }

Page 49: CHAPTER 2

positioning2.html2 of 2

23 </style> 24 </head> 25 26 <body> 27 28 <p>The text at the end of this sentence 29 <span class = "super">is in superscript</span>.</p> 30 31 </body> 32 </html>

Output:

Page 50: CHAPTER 2

Backgrounds

• background-image– Specifies the image URL– Can also set background-color property in

case the image is not found• background-position

– Places the image on the page– Some of the values: top, bottom, center, left,

right

Page 51: CHAPTER 2

Backgrounds

– All above values are used individually or combination for vertical and horizontal positioning.

– Example: To position the image as horizontally centered(positioned at 50% of the distance across the screen) and 30 pixels from the top, use: background-position: 50% 30px;

Page 52: CHAPTER 2

Backgrounds

• background-repeat– Controls the tiling of the background image– Possible values: no-repeat, repeat, repeat-x

(tile the image horizontally), repeat-y (tile the image vertically)

• background-attachment– Fixed (fix the image in the position specified

by background-position)– Scroll (moves the image when user scrolls

through the document)

Page 53: CHAPTER 2

Backgrounds

• font-weight– Specify the “boldness” of text– Possible values: bold, normal, bolder, lighter

• font-style– Possible values: none, italic, oblique (will

default to italic if the system does not support oblique text.)

Page 54: CHAPTER 2

background.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.10: background.html --> 6 <!-- Adding background images and indentation --> 7 8 <html xmlns = "http://www.w3 .org/1999/xhtml"> 9 <head> 10 <title>Background Images</title> 11 12 <style type = "text/css"> 13 14 body { background-image: url(logo.gif); 15 background-position: bottom right; 16 background-repeat: no-repeat; 17 background-attachment: fixed; } 18 19 p { font-size: 18pt; 20 color: #aa5588; 21 text-indent: 1em; 22 font-family: arial, sans-serif; } 23 24 .dark { font-weight: bold; } 25

Page 55: CHAPTER 2

background.html(2 of 2)

26 </style> 27 </head> 28 29 <body> 30 31 <p> 32 This example uses the background-image, 33 background-position and background-attachment 34 styles to place the <span class = "dark">Deitel 35 &amp; Associates, Inc.</span> logo in the bottom, 36 right corner of the page. Notice how the logo 37 stays in the proper position when you resize the 38 browser window. 39 </p> 40 41 </body> 42 </html>

Page 56: CHAPTER 2
Page 57: CHAPTER 2

Alignment of Text

• The text-indent property can be used to indent the first line of a paragraph.

• The float property is used to specify that text should flow around some element, often an image or a table.

• The possible values for float are left, right, and none, which is the default.

Page 58: CHAPTER 2

Alignment of Text

<html><head><style type="text/css"> p.indent {text-indent: 0.5in}</style></head><body><p class="indent">

A Web programmer or Web developer is the person in charge of making the website do things. They create the interactivity on the site including the actions on forms, rollovers for menus, and any Ajax or other programmming on the site.

</p></body></html>

Page 59: CHAPTER 2

Alignment of Text

A Web programmer or Web developer is the person in charge of making the website do things. They create the interactivity on the site including the actions on forms, rollovers for menus, and any Ajax or other programmming on the site.

Page 60: CHAPTER 2

Alignment of Text

<html><head><style type="text/css"> img {float: right}</style></head><body><p> <img src="web.jpg" width="100" height="100" /></p><p>A Web programmer or Web developer is the person in charge of making the website do things. They create the interactivity on the site including the actions on forms, rollovers for menus, and any Ajax or other programmming on the site.</p></body></html>

Page 61: CHAPTER 2

The Box Model

Outer Edge

Margin

Padding

Content

Border

Page 62: CHAPTER 2

The Box Model

• Box model– Margins

• margin-top, margin-right, margin-left, margin-bottom

– Padding• padding-top, padding-right, padding-left, and padding-bottom

– Border• border-width

– thin, medium, thick• border-color

– Sets the color• border-style

– none, hidden, dotted, dashed, solid, double, groove, ridge, inset and outset

Page 63: CHAPTER 2

floating.html(1 of 3)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.12: floating.html --> 6 <!-- Floating elements and element boxes --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Flowing Text Around Floating Elements</title> 11 12 <style type = "text/css"> 13 14 div { background-color: #ffccff; 15 margin-bottom: .5em; 16 font-size: 1.5em; 17 width: 50% } 18 19 p { text-align: justify } 20 21 </style> 22 23 </head> 24

Page 64: CHAPTER 2

floating.html(2 of 3)

25 <body> 26 27 <div style = "text-align: center"> 28 Deitel &amp; Associates, Inc.</div> 29 30 <div style = "float: right; margin: .5em; 31 text-align: right"> 32 Corporate Training and Publishing</div> 33 34 <p>Deitel &amp; Associates, Inc. is an internationally 35 recognized corporate training and publishing organization 36 specializing in programming languages, Internet/World 37 Wide Web technology and object technology education. 38 The company provides courses on Java, C++, Visual Basic, C, 39 Internet and World Wide Web programming, and Object Technology.</p> 40 41 <div style = "float: right; padding: .5em; 42 text-align: right"> 43 Leading-Edge Programming Textbooks</div> 44 45 <p>The company's clients include many Fortune 1000 46 companies, government agencies, branches of the military 47 and business organizations.</p> 48

Page 65: CHAPTER 2

floating.html(3 of 3)

49 <p style = "clear: right">Through its publishing 50 partnership with Prentice Hall, Deitel &amp; Associates, 51 Inc. publishes leading-edge programming textbooks, 52 professional books, interactive CD-ROM-based multimedia 53 Cyber Classrooms, satellite courses and World Wide Web 54 courses.</p> 55 56 </body> 57 </html>

Page 66: CHAPTER 2

• <p style=“clear: right”>…..</p>(line 49)

• Possible values of clear = right, left• By setting clear property to the same

direction as that in which the elements is floated (right or left), you can interrupt the flow of text around a floated element.

Page 67: CHAPTER 2

borders.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.14: borders.html --> 6 <!-- Setting borders of an element --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Borders</title> 11 12 <style type = "text/css"> 13 14 body { background-color: #ccffcc } 15 16 div { text-align: center; 17 margin-bottom: 1em; 18 padding: .5em } 19 20 .thick { border-width: thick } 21 22 .medium { border-width: medium } 23 24 .thin { border-width: thin } 25

Page 68: CHAPTER 2

borders.html(2 of 2)

26 .groove { border-style: groove } 27 28 .inset { border-style: inset } 29 30 .outset { border-style: outset } 31 32 .red { border-color: red } 33 34 .blue { border-color: blue } 35 36 </style> 37 </head> 38 39 <body> 40 41 <div class = "thick groove">This text has a border</div> 42 <div class = "medium groove">This text has a border</div> 43 <div class = "thin groove">This text has a border</div> 44 45 <p class = "thin red inset">A thin red line...</p> 46 <p class = "medium blue outset"> 47 And a thicker blue line</p> 48 49 </body> 50 </html>

Page 69: CHAPTER 2
Page 70: CHAPTER 2

borders2.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.15: borders2.html --> 6 <!-- Various border-styles --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Borders</title> 11 12 <style type = "text/css"> 13 14 body { background-color: #ccffcc } 15 16 div { text-align: center; 17 margin-bottom: .3em; 18 width: 50%; 19 position: relative; 20 left: 25%; 21 padding: .3em } 22 </style> 23 </head> 24 25 <body>

Page 71: CHAPTER 2

borders2.html(2 of 2)

26 27 <div style = "border-style: solid">Solid border</div> 28 <div style = "border-style: double">Double border</div> 29 <div style = "border-style: groove">Groove border</div> 30 <div style = "border-style: ridge">Ridge border</div> 31 <div style = "border-style: inset">Inset border</div> 32 <div style = "border-style: outset">Outset border</div> 33 34 </body> 35 </html>

Page 72: CHAPTER 2

Margins and Padding

<html><head><style type="text/css">p.one {margin:0.1in;

padding:0.3in; background-color:#C0C0Co; border-style:solid;}

</style></head><body>

<p class="one">margin= 0.1in, padding=0.3in</p></body></html>

Page 73: CHAPTER 2

Margins and Padding

margin =0.1inpadding =0.3in

Page 74: CHAPTER 2

User Style Sheets

• User defines format of pages based on their preferences.

• Conflicts may occur between author styles and user styles.

• User_absolute.html- If users define their own font-size in a user style sheet, the author has a higher precedence and overrides the user style.

• The font size is too small for above file.

Page 75: CHAPTER 2

User_absolute.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.16: user_absolute.html --> 6 <!-- User styles --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>User Styles</title> 11 12 <style type = "text/css"> 13 14 .note { font-size: 9pt } 15 16 </style> 17 </head> 18 19 <body> 20 21 <p>Thanks for visiting my Web site. I hope you enjoy it. 22 </p><p class = "note">Please Note: This site will be 23 moving soon. Please check periodically for updates.</p>

Page 76: CHAPTER 2

User_absolute.html(2 of 2)

24 25 </body> 26 </html>

Page 77: CHAPTER 2

userstyles.css1 of 1

1 /* Fig. 6.17: userstyles.css */ 2 /* A user stylesheet */ 3 4 body { font-size: 20pt; 5 color: yellow; 6 background-color: #000080 }

Page 78: CHAPTER 2

User Style Sheets

Fig. 6.18 User style sheet in Internet Explorer 6.

Page 79: CHAPTER 2

User Style Sheets

Fig. 6.19 User style sheet applied with pt measurement.

Page 80: CHAPTER 2

80

User Style Sheets

• Developer/author are advised to use relative measurements (e.g: em or ex) instead of absolute measurements(e.g:pt).-Refer to slide 99

• User_relative.html- the font-size has been changed to .75 em. This will not override the user style sheet. Font size displayed is relative to the one specified in the user style sheet.

Page 81: CHAPTER 2

User_relative.html(1 of 2)

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4 5 <!-- Fig. 6.20: user_relative.html --> 6 <!-- User styles --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>User Styles</title> 11 12 <style type = "text/css"> 13 14 .note { font-size: .75em } 15 16 </style> 17 </head> 18 19 <body> 20 21 <p>Thanks for visiting my Web site. I hope you enjoy it. 22 </p><p class = "note">Please Note: This site will be 23 moving soon. Please check periodically for updates.</p>

20 pt0.75 em X 20 pt = 15 pt

Page 82: CHAPTER 2

User_relative.html(2 of 2)

24 25 </body> 26 </html>

Page 83: CHAPTER 2

User Style Sheets

Fig. 6.21 User style sheet applied with em measurement.

Page 84: CHAPTER 2

References

• CSS Propertieshttp://htmlhelp.com/reference/css/properties.html

• CSS Reference & Properties

http://www.w3schools.com/CSS/CSS_reference.asp

• Pick Brains: CSS

http://www.pickbrains.com/articles/cascading-style-sheets-css-tutorial-usage

84


Recommended