 2002 Prentice Hall, Inc. All rights reserved. Chapter 4 – Cascading Style Sheets (CSS) Objectives –To take control of the appearance of a Web site by.

Slides:



Advertisements
Similar presentations
1 Cascading Style Sheets™ (CSS) Outline 5.1 Introduction 5.2 Inline Styles 5.3 Embedded Style Sheets 5.4 Conflicting Styles 5.5 Linking External Style.
Advertisements

1 Dynamic HTML: Cascading Style Sheets™ (CSS). 2 Introduction Cascading Style Sheets (CSS) –Specify the style of your page elements –Spacing, margins,
1 XHTML Cascading Style Sheets™ (CSS). 2 Inline.html 1 2
Background: HTML and CSS Chapters 1-4 of Deitel XML text.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 4 – Cascading Style Sheets (CSS) Outline 4.1Introduction 4.2Inline Styles 4.3Creating Style Sheets.
Presentation (5): Cascading Style Sheets (CSS) ITNET1.
CASCADING STYLE SHEETS CSS. 2 What CSS means?  CSS is an extension to basic HTML that allows you to style your web pages.  It separates the part that.
Cascading Style Sheets SP.772 May 6, CSS Useful for creating one unified look for an entire web site. Helps to seperate style from content. Can.
1 Dynamic HTML -Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style Sheets 6.4 Conflicting Styles 6.5 Linking External.
4.01 Cascading Style Sheets
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
Selectors thru Borders. CSS – Cascading Style Sheets – is a way to style HTML HTML is the content base of a web page CSS provides the presentation qualities.
CSS1-1 Cascading Style Sheets (CSS) Xingquan (Hill) Zhu
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Cascading Style Sheets CS3505. What are CSS? Method for adding style attributes consistently to HML tags Cascading because styles are applied in order.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 14 – Dynamic HTML: Cascading Style Sheets (CSS) Outline 14.1Introduction 14.2Inline Styles.
CSS Dvijesh Bhatt.
Cascading style sheets (CSS)
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
Cascading Style Sheet (CSS)
1Computer Sciences Department. And use
Cascading Style Sheets CSS. CSS - Structure Declaration block Property: identifies what to change Value: how to change it Selector – example h1{ font-size:
Tutorial 6 By Sam INE 1020 Introduction to Internet Engineering 1 DHTML & CSS Tutorial 6.
CSS in XHTML continued Please use speaker notes for additional information!
1 WDMD 170 – UW Stevens Point WDMD 170 Internet Languages eLesson: CSS Introduction to Style Sheets (NON-audio version) © Dr. David C. Gibbs
Website Development & Management Working with Style Rules Instructor: John Seydel, Ph.D. CIT Fall
CIS 1315 – Web Development for Educators CIS 1315 HTML Tutorials 3 & 4: Working With CSS.
CSS My favourite ICT lesson By Federico Boschi Cascading Style Sheets.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 3.
MySQL and PHP Review CSS. Cascading Style Sheet (CSS) Style sheets are files or forms that describe the layout and appearance of a document. Cascading.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
Lesson 03 // Cascading Style Sheets. CSS Stands for Cascading Style Sheets. We’ll be using a combination of Html and CSS to create websites. CSS is a.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
ECA225 Applied Interactive Programming Cascading Style Sheets, pt 1 ECA 225 Applied Online Programming.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 6 - Cascading Style Sheets™ (CSS) Outline 6.1 Introduction 6.2 Inline Styles 6.3 Embedded Style.
 Cascading Style Sheets (CSS) ◦ Used to specify the presentation of elements separately from the structure of the document.  Inline style ◦ declare.
CHAPTER 2 CSS (Cascading Style Sheet). Topics Introduction Inline Styles Embedded Style Sheets Conflicting Styles Linking External Style Sheets Positioning.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
Cascading Style Sheets Eugenia Fernandez IUPUI. CSS Purpose CSS allow you to specify the style in which your XML elements are displayed. CSS were originally.
Presentation (5): Cascading Style Sheets (CSS) Fundamentals of Web-Centric Development.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
Introduction to CSS September 20, Introduction Cascading Style Sheets (CSS) –Separation of structure from presentation CSS guide and tutorial.
1 Introduction to Web Application Introduction to Cascading Style Sheet.
1 CS428 Web Engineering Lecture 08 Border, Margin, Padding … (CSS - III)
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
3.2 Cascading Style Sheets. 2 Positioning Elements Normally, elements are laid out on the page in the order that they are defined in the XHTML document.
5 th ed: Chapter 4 4 th ed: Chapter 5 SY306 Web and Databases for Cyber Operations Slide Set #4: CSS.
Web Technologies Beginning Cascading Style Sheets (CSS) 1Copyright © Texas Education Agency, All rights reserved.
CSS: Cascading Style Sheets Part II. Style Syntax.
Cascading Style Sheets (CSS)
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
Tutorial #5 Working with the Box Model. Tutorial #4 Review - CSS Create a homework page Final Project Discussion Exam on Blackboard Styling Lists (List-style-type,
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
HTML & CSS Contents: the different ways we can use to apply CSS to The HTML documents CSS Colors and Background CSS Fonts CSS Text CSS box model: padding,
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Internet & World Wide Web How to Program, 5/e 1. 2.
Chapter 6 - Cascading Style Sheets™ (CSS)
Cascading Style Sheets™ (CSS)
Chapter 26 - Bonus: Cascading Style Sheets (CSS)
Cascading Style Sheets
Cascading Style Sheets™ (CSS)
Cascading Style Sheets™ (CSS)
Presentation transcript:

 2002 Prentice Hall, Inc. All rights reserved. Chapter 4 – Cascading Style Sheets (CSS) Objectives –To take control of the appearance of a Web site by creating style sheets –To use a style sheet to give all the pages of a Web site 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 and model and be able to control the margins, borders and padding –To use style sheets to separate presentation from content “Fashion fade, style is eternal”

 2002 Prentice Hall, Inc. All rights reserved. Outline 4.1Introduction 4.2Inline Styles 4.3Creating Style Sheets with the style Element 4.4Conflicting Styles 4.5Linking External Style Sheets 4.6Positioning Elements 4.7Backgrounds 4.8Element Dimensions 4.9Text Flow and the Box Model 4.10User Style Sheets

 2002 Prentice Hall, Inc. All rights reserved. 4.1 Introduction Cascading Style Sheets (CSS) –Define document style –Separate structure from presentation Greater manageability and easier changes There are three levels of style sheets –Inline - specified for a specific occurrence of a tag and apply only to that tag This is fine-grain style, which defeats the purpose of style sheets - uniform style –Document-level style sheets - apply to the whole document in which they appear –External style sheets - can be applied to any number of documents (Can be validated through the following web site:

 2002 Prentice Hall, Inc. All rights reserved. Style Specifications Format Inline style style = “attr_1 : value_1; attr_2 : value_2; …….; attr_n : value_n” Document and external style <!-- /*this is for browser only*/ rule list selector { attr_1 : value_1; ….; attr_n : value_n; } --> –“selector”: tag or tags affected by the rule

 2002 Prentice Hall, Inc. All rights reserved. 4.2 Inline Styles Attribute Style –Define style in document Each element is followed by colon ( : ) then value Inline styles override all other styles It’s so trivial, not really reflect the principles of unifying document structure.

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.1Inline styles. Lines 18 and 21 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Inline Styles This text does not have any style applied to it This text has the font-size 19 style applied to it, making it 20pt This text has the 22 font-size and color styles applied to it, 23 making it 20pt. and blue Define style for following text

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.1

 2002 Prentice Hall, Inc. All rights reserved. 4.3 Creating Styles with the style element (Document Specifications) Styles –Declared in head of document –May be applied to whole document –Begin Define styles attached to tags Property followed by colon ( : ) Multiple properties separated by semi-colon ( ; )

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.2Declaring styles in the head of a document. Line 12 Lines Line 21 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Style Sheets em { background-color: #8000ff; 15 color: white } h1 { font-family: arial, sans-serif } p { font-size: 14pt } special { color: blue } Start of style sheetDefine style attributes of em, h1, and p tags Define special case (not attached to any pre-defined tag)

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.2Declaring styles in the head of a document. (Part 2) Line Deitel & Associates, Inc Deitel & Associates, Inc. is an internationally recognized 32 corporate training and publishing organization specializing 33 in programming languages, Internet/World Wide Web technology 34 and object technology education. Deitel & Associates, Inc. is 35 a member of the World Wide Web Consortium. The company 36 provides courses on Java, C++, Visual Basic, C, Internet and 37 World Wide Web programming, and Object Technology Clients 40 The company's clients include many 41 Fortune 1000 companies, government agencies, branches 42 of the military and business organizations. Through its 43 publishing partnership with Prentice Hall, Deitel & Associates, 44 Inc. publishes leading-edge programming textbooks, professional 45 books, interactive CD-ROM-based multimedia Cyber Classrooms, 46 satellite courses and World Wide Web courses Using special style

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.2

 2002 Prentice Hall, Inc. All rights reserved. 4.4 Conflicting Styles Style precedence –Author > User > Agent (Web Browser)

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.3Inheritance in style sheets. Line 13 Lines Line 15 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - More Styles a.nodec { text-decoration: none } a:hover { text-decoration: underline; 16 color: red; 17 background-color: #ccffcc } li em { color: red; 20 font-weight: bold } ul { margin-left: 75px } ul ul { text-decoration: underline; 25 margin-left: 15px } Assign attribute nodec to all a elements (override default underline attribute of element a ) Define style for any em element contained in li tag A pseudo-class, dynamically activated by users

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.3Inheritance in style sheets. (Part 2) Shopping list for Monday : Milk 36 Bread White bread 39 Rye bread 40 Whole wheat bread Rice 44 Potatoes 45 Pizza with mushrooms Go to the Grocery 49 store

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.3

 2002 Prentice Hall, Inc. All rights reserved. 4.5 Linking External Style Sheets External Style Sheets –Contained in a.css file –Single style sheet used easily between multiple pages How to refer to external style specifications? Note: can only be placed in the “head” element

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.4An external style sheet (styles.css). Lines /* Fig. 4.4: styles.css */ 2/* An external stylesheet */ 3 4a { text-decoration: none } 5 6a:hover { text-decoration: underline; 7 color: red; 8 background-color: #ccffcc } 9 10li em { color: red; 11 font-weight: bold} 12 13ul { margin-left: 2cm } 14 15ul ul { text-decoration: underline; 16 margin-left:.5cm } Define attributes used for linking documents

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.5Linking an external style sheet. Line 11 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Importing Style Sheets Link external stylesheet with current document, Only appear in “head”

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.5Linking an external style sheet. (Part 2) Shopping list for Monday : Milk 19 Bread White bread 22 Rye bread 23 Whole wheat bread Rice 27 Potatoes 28 Pizza with mushrooms Go to the Grocery store

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.5

 2002 Prentice Hall, Inc. All rights reserved. 4.6 Positioning Elements CSS property position –Controlling the positioning of elements in an HTML document –Capability_1: absolute positioning Define element location in pixels Location is not defined by browser –Capability_2: relative positioning Related to current position

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.6Positioning elements with CSS. Lines <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Absolute Positioning <img src = "i.gif" style = "position: absolute; top: 0px; 15 left: 0px; z-index: 1" alt = "First positioned image"> 16 <p style = "position: absolute; top: 50px; left: 50px; 17 z-index: 3; font-size: 20pt;">Positioned Text 18 <img src = "circle.gif" style = "position: absolute; top: 25px; 19 left: 100px; z-index: 2" alt = "Second positioned image"> Use inline style to position images: place second image over the first (because second image has higher z index)

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.6

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.7Relative positioning of elements. Lines <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Relative Positioning p { font-size: 1.3em; 14 font-family: verdana, arial, sans-serif } span { color: red; 17 font-size:.6em; 18 height: 1em } super { position: relative; 21 top: -1ex } sub { position: relative; 24 bottom: -1ex } 25 Define attributes that position elements relative to browser-defined location

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.7Relative positioning of elements. (Part 2) 26.shiftleft { position: relative; 27 left: -1ex } shiftright { position: relative; 30 right: -1ex } The text at the end of this sentence 38 is in superscript The text at the end of this sentence 41 is in subscript The text at the end of this sentence 44 is shifted left The text at the end of this sentence 47 is shifted right

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.7

 2002 Prentice Hall, Inc. All rights reserved. 4.7 Backgrounds CSS gives control over backgrounds –Property background-image Specify image URL –Property background-color Specify background color –Property background-position Specifies background location –Property background-repeat Specifies background tiling –Property background-attachment Set to fixed to apply background-position

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.8Adding a background image with CSS. Line 14 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Background Images body { background-image: url(logo.gif); 14 background-position: bottom right; 15 background-repeat: no-repeat; 16 background-attachment: fixed; } p { font-size: 18pt; 19 color: #aa5588; 20 text-indent: 1em; 21 font-family: arial, sans-serif; } dark { font-weight: bold; } allocate image by using “url”Place image at bottom-right of screen

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.8Adding a background image with CSS. (Part 2) This example uses the background-image, 32 background-position and background-attachment 33 styles to place the Deitel 34 & Associates, Inc. logo in the bottom, 35 right corner of the page. Notice how the logo 36 stays in the proper position when you resize the 37 browser window

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.8

 2002 Prentice Hall, Inc. All rights reserved. 4.8 Element Dimensions Specify element dimensions –Set style attribute width to stretch applied elements

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.9Setting box dimensions and aligning text. Line 21 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Box Dimensions div { background-color: #ffccff; 14 margin-bottom:.5em } Here is some 22 text that goes in a box which is 23 set to stretch across twenty precent 24 of the width of the screen. 25 Place contained text in box that occupies 20% of screen

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.9Setting box dimensions and aligning text. (Part 2) Here is some CENTERED text that goes in a box 28 which is set to stretch across eighty precent of 29 the width of the screen This box is only twenty percent of 33 the width and thirty percent of the height. 34 What do we do if it overflows? Set the 35 overflow property to scroll!

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.9

 2002 Prentice Hall, Inc. All rights reserved. 4.9 Text Flow and the Box Model Floating –Allows repositioning of elements Nearby text will wrap clear property overrides wrapping Margin –Defines size of element’s margins

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.10Floating elements, aligning text and setting box dimensions. 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Flowing Text Around 10 Floating Elements div { background-color: #ffccff; 15 margin-bottom:.5em; 16 font-size: 1.5em; 17 width: 50% } p { text-align: justify; }

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.10Floating elements, aligning text and setting box dimensions. (Part 2) Line Deitel & Associates, Inc Corporate Training and Publishing Deitel & Associates, Inc. is an internationally recognized 33 corporate training and publishing organization specializing 34 in programming languages, Internet/World Wide Web technology 35 and object technology education. Deitel & Associates, 36 Inc. is a member of the World Wide Web Consortium. The company 37 provides courses on Java, C++, Visual Basic, C, Internet and 38 World Wide Web programming, and Object Technology Leading-edge Programming Textbooks The company's clients include many Fortune 1000 companies, 44 government agencies, branches of the military and business 45 organizations. Through its publishing partnership with Prentice 46 Hall, Deitel & Associates, Inc. publishes leading-edge 47 programming textbooks, professional books, interactive 48 CD-ROM-based multimedia Cyber Classrooms, satellite courses 49 and World Wide Web courses. Here 50 is some unflowing text. Here is some unflowing text Float text in box on right-side with.5 -pixel margin

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.10

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.12Applying borders to elements. Lines <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Borders body { background-color: #ccffcc } div { text-align: center; 16 margin-bottom: 1em; 17 padding:.5em } thick { border-width: thick } medium { border-width: medium } thin { border-width: thin } groove { border-style: groove } inset { border-style: inset } 28 Define various borders

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.12Applying borders to elements. (Part 2) 29.outset { border-style: outset } red { border-color: red } blue { border-color: blue } This text has a border 41 This text has a border 42 This text has a border A thin red line And a thicker blue line Multi-classes applied

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.12

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.13Various border-styles. 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - Borders body { background-color: #ccffcc } div { text-align: center; 16 margin-bottom:.3em; 17 width: 50%; 18 position: relative; 19 left: 25%; 20 padding:.3em }

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.13Various border-styles. (Part 2) Lines Solid border 28 Double border 29 Groove border 30 Ridge border 31 Inset border 32 Outset border Define various border styles

 2002 Prentice Hall, Inc. All rights reserved. Output for Fig. 4.13

 2002 Prentice Hall, Inc. All rights reserved User Style Sheets User-defined styles –Users can customize styles e.g., Web-site designers

 2002 Prentice Hall, Inc. All rights reserved. Outline Fig. 4.14Modifying text size with the em measurement. Line 13 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 " XML How to Program - User Styles note { font-size: 1.5em } Thanks for visiting my Web site. I hope you enjoy it. 21 Please Note: This site will be moving soon. 22 Please check periodically for updates Modify user-defined stylesheet by multiplying em style by 1.5

 2002 Prentice Hall, Inc. All rights reserved. Adding your own style sheet in IE Internet options  Accessibility  User Style Sheet