Chapter 6 Cascading Style Sheets™ (CSS)

Slides:



Advertisements
Similar presentations
Intro To Cascading Style Sheets By Mario Yannakakis.
Advertisements

CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
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.
Cascading Style Sheets Basics. Why use Cascading Style Sheets? Allows you to set up a series of rules for all pages in a site. The series may be changed.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
Part 3 Introduction to CSS. CSS Text Text Styles h1 {color: green} // rgb(0,255,0), #00ff00 h2{letter-spacing: 0.5cm} // 2px h3 {text-align: right} //
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
 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.
Using Cascading Style Sheets CSS Basics. Goals Understand basic syntax of Cascading Style Sheets (CSS) Understand basic syntax of Cascading Style Sheets.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic CSS: Cascading Style Sheets.
Using Cascading Style Sheets CSS Structure. Goals Understand how contextual, class and ID selectors work Understand how contextual, class and ID selectors.
Lecture 7 Cascading Style Sheets (CSS) Boriana Koleva Room: C54
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
Pre-Module CSS BTM 395: Internet Programming. Cascading Style Sheets (CSS) Separation of structure from presentation CSS guide and tutorial –
TECH2018 Multimedia and the Internet More about CSS and Page Layouts.
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,
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 3.
 2008 Pearson Education, Inc. All rights reserved Cascading Style Sheets™ (CSS)
 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.
Cascading Style Sheets Objective: Create an external style sheet, embedded style sheet, and an inline style to change the look and feel of a web site.
Introduction to CSS September 20, Introduction Cascading Style Sheets (CSS) –Separation of structure from presentation CSS guide and tutorial.
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,
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
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.
CSS Cascading Style Sheets
Instructor: Sergey Goldman
Cascading Style Sheets™ (CSS)
Web Development & Design Foundations with XHTML
Chapter 6 - Cascading Style Sheets™ (CSS)
CS3220 Web and Internet Programming CSS Basics
Cascading Style Sheets™ (CSS)
CSS: Cascading Style Sheets
Introducing :CSS Cascading Style Sheets in 5 Lessons.
CSS Rule Selector Declaration Block Value Attribute Name body {
Cascading Style Sheets
IS 360 Declaring CSS Styles
Chapter 3 Style Sheets: CSS
CX Introduction to Web Programming
3.1 Introduction - The CSS1 specification was developed in 1996
Using Cascading Style Sheets Module B: CSS Structure
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Cascading Style Sheet (CSS)
Cascading Style Sheets
CSS Applications to XML 19-Sep-18.
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Introduction to CSS.
Second CSS Lecture Applications to XML
Software Engineering for Internet Applications
Web Programming– UFCFB Lecture 11
What are Cascading Stylesheets (CSS)?
Cascading Style Sheets
Cascading Style Sheets™ (CSS)
Web Development & Design Foundations with H T M L 5
More CSS 22-Feb-19.
Tutorial 3 Working with Cascading Style Sheets
CS3220 Web and Internet Programming CSS Basics
CS3220 Web and Internet Programming CSS Basics
Cascading Style Sheets
CSS Applications to XML 20-May-19.
Stylin’ with CSS.
CSS Applications to XML 3-Jul-19.
Introduction to Cascading Style Sheets (CSS)
Cascading Style Sheets™ (CSS)
CGS 3066: Web Programming and Design Fall 2019
Presentation transcript:

Chapter 6 Cascading Style Sheets™ (CSS) Internet & World Wide Web: How to Program Deitel, Deitel & Goldburg Fall 2007 Yanjun Li CSRU2350

Cascading Style Sheets (CSS) We shift our focus to formatting and presenting information. Separation of structure from presentation To simplify maintaining and modifying a web page Three ways to define the style of XHTML files External Style Sheet Embedded Style Sheet Inline Style Fall 2007 Yanjun Li CSRU2350

Cascading Style Sheets (CSS) Separation of structure from presentation Inline Styles Declare an individual element’s format Attribute style inside a single XHTML element CSS property Properties background-color, color Properties font-family, font-size Followed by a colon and a value For example: <p style = “font-size: 20pt; color: #0000ff”> your paragraph</p> Fall 2007 Yanjun Li CSRU2350

Inline Styles Fall 2007 Yanjun Li CSRU2350

Example inline <html> <body> <p>This text does not have any style applied to it.</p> <p style = "font-size: 20pt"> This text has the <em>font-size</em> style applied to it, making it 20pt.</p> <p style = "font-size: 20pt; color: #6666ff"> This text has the <em>font-size</em> and <em>color</em> styles applied to it, making it 20pt. and light blue.</p> </body> </html> Fall 2007 Yanjun Li CSRU2350

Color property body { color:red; } h1 { color:#00ff00; } p { color:rgb(0,0,255); } Fall 2007 Yanjun Li CSRU2350

2.Embedded Style Sheets Embed an entire CSS document in an XHTML document’s head element. To achieve separation between the CSS code and the XHTML Element style Attribute type describes a file’s content using Multipurpose Internet Mail Extensions (MIME) type Example: <style type=“text/css”> </style> Fall 2007 Yanjun Li CSRU2350

CSS Rules For an element in XHTML, you can specify a displaying rule The body of each rule is enclosed in { }. Properties background-color, color Properties font-family, font-size Example : li, p {color: red; font-size: 12pt} Fall 2007 Yanjun Li CSRU2350

Style Class Defines styles that can be applied to any type of element. The declaration: .special {. . . } Attribute class of an XHTML element is used to apply a style class: Example : <p class=“special”> Fall 2007 Yanjun Li CSRU2350

Example <head> <title>Style Sheets</title> <style type = "text/css"> em { font-weight: bold; color: black } h1 { font-family: tahoma, helvetica, sans-serif } p { font-size: 12pt; font-family: arial, sans-serif } .special { color: #6666ff } </style> </head> Fall 2007 Yanjun Li CSRU2350

font-size property 12-point Relative values— xx- small, x-small, small, smaller, medium, large, larger, x-large and xx-large— Fall 2007 Yanjun Li CSRU2350

Fall 2007 Yanjun Li CSRU2350

Font family/ font-family: tahoma, helvetica, sans-serif The browser attempts to use the fonts in the order they appear in the list. It’s advisable to end a font list with a generic font family name in case the other fonts are not installed on the user’s computer. In this example, if the tahoma font is not found on the system, the browser will look for the helvetica font. If neither is found, the browser will display its default sans-serif font. Fall 2007 Yanjun Li CSRU2350

3.Linking External Style Sheets Can provide uniform look and feel to entire site File extension : styles.css CSS comments : /* ….*/ Element link in the head section of the XHTML document : <link rel = “stylesheet” type=“text/css” href=“styles.css” /> Fall 2007 Yanjun Li CSRU2350

Conflicting Styles (1) Cascading: all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority: Browser default External style sheet Embedded style sheet (inside the <head> tag) Inline style (inside an HTML element) Fall 2007 Yanjun Li CSRU2350

Conflicting Styles (2) Inheritance : Child (nested) element inherits styles of parent element. Descendant’s properties have greater specificity than ancestor’s properties. Child’s style > Parent’s style Fall 2007 Yanjun Li CSRU2350

Grouping Element XHTML Element span : a grouping/inline-level element. Apply CSS rules to a block of text. XHTML Element div: a similar element, but display on its own line, with margins above and below (a block-level element). Fall 2007 Yanjun Li CSRU2350

Length Measurement Relative-length Measurement is based on screen resolution. px (pixels) : margin-left: 75px em (height of an uppercase M) : font-size: 1.5em ex (height of a lowercase x) Absolute-length Measurement in (inches), cm (centimeters), mm (millimeters), pt (points, 1 pt = 1/72 in), pc (picas, 1 pc = 12 pt). Fall 2007 Yanjun Li CSRU2350

In next lecture Fall 2007 Yanjun Li CSRU2350

Font font-size sets the size of a font xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger, XXpt, xx% font-family: a prioritized list of font family names and/or generic family names for an element arial, sans-serif font-weight sets the weight of a font normal, bold, bolder, lighter, 100 ~ 900 font-style sets the style of the font normal, italic, oblique Fall 2007 Yanjun Li CSRU2350

2.6 Backgrounds background-image specifies the image URL background-position places the image on the page background-repeat controls the tiling of the background image background-attachment fixed scroll Fall 2007 Yanjun Li CSRU2350

background.html (1 of 2) Fall 2007 Yanjun Li CSRU2350

background.html (2 of 2) Fall 2007 Yanjun Li CSRU2350

Fall 2007 Yanjun Li CSRU2350

2.7 Element Dimensions CSS rules can specify the actual dimensions of each page element Example: style=“width:20%; height:30%” Fall 2007 Yanjun Li CSRU2350

width.html (1 of 2) Fall 2007 Yanjun Li CSRU2350

width.html (2 of 2) Fall 2007 Yanjun Li CSRU2350

2.5 Positioning Elements Absolute positioning Relative positioning Property position: “position : absolute;” Properties top, left, right, bottom The distances from margins of its containing block-level element. z-index attribute Layer overlapping elements properly, higher in front of lower value. Relative positioning Elements are positioned relative to other elements Property position : “position : relative; ” Fall 2007 Yanjun Li CSRU2350

positioning.html (1 of 1) Fall 2007 Yanjun Li CSRU2350

Fall 2007 Yanjun Li CSRU2350

positioning2.html (1 of 2) Fall 2007 Yanjun Li CSRU2350

positioning2.html 2 of 2 Fall 2007 Yanjun Li CSRU2350

Fall 2007 Yanjun Li CSRU2350

6.12 Web Resources www.w3.org/TR/css3-roadmap www.ddj.com/webreview/style tech.irt.org/articles/css.htm Fall 2007 Yanjun Li CSRU2350

W3C CSS Validation Service Validates external CSS documents Ensures that style sheets are syntactically correct jigsaw.w3.org/css-validator/validator-upload.html Fall 2007 Yanjun Li CSRU2350

Reference Reproduced from the PowerPoints for Internet & World Wide Web How to Program, 3e by Deitel, Deitel and Goldberg © 2004. Reproduced by permission of Pearson Education, Inc. Fall 2007 Yanjun Li CSRU2350