Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.

Slides:



Advertisements
Similar presentations
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Advertisements

© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
CIS 1310 – HTML & CSS 6 Layout. CIS 1310 – HTML & CSS Learning Outcomes  Describe & Apply the CSS Box Model  Configure Float with CSS  Designate Positioning.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
Chapter 6 Web Typography
INTRODUCTORY Tutorial 3 Using CSS to Format Multiple Pages.
Lecture Cascading Style Sheets (CSS) Internal Style Sheets Classes.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic CSS: Cascading Style Sheets.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
Chapter 11 Cascading Style Sheets: Part I The Web Warrior Guide to Web Design Technologies.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
Chapter 7 Web Typography Principles of Web Design, 4 th Edition.
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets.
Using Styles and Style Sheets for Design
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
Cascading Style Sheet (CSS)
MORE Cascading Style Sheets (The Positioning Model)
New Perspectives on XML, 2nd Edition Tutorial 5 1 TUTORIAL 5 WORKING WITH CASCADING STYLE SHEETS.
XP New Perspectives on XML Tutorial 5 1 TUTORIAL 5 CSS Tutorial – Carey ISBN
Chapter 6 Web Typography. 2 Principles of Web Design Chapter 5 Objectives Understand principles for type design on a Web site Use the element Understand.
Tutorial 4 Creating Special Effects with CSS
CSS Positioning Creating Special Effects with CSS CS202 Working with Cascading Style Sheets (Chapter 4) CS202 1.
1 Cascading Style Sheets (CSS) Part 2. 2 The Sources of Style Sheets.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
Doman’s Sections Information in this presentation includes text and images from
Cascading Style Sheets by Pavlovic Nenad by. Presentation Contents  What is CSS?  Why CSS?  Types of Style Sheets  Style Sheets Syntax  Box Formatting.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
Part 1: CSS - Why? - How it works - Writing rules - Examples.
CIS67 Foundations for Creating Web Pages Professor Al Fichera Rev. September 14, 2010—All HTML code brought to XHTML standards. Reference for CIS127 and.
CIS 1315 – Web Development for Educators CIS 1315 HTML Tutorials 3 & 4: Working With CSS.
Cascading Style Sheets CSS by Pavlovic Nenad by. 2Cascading Style Sheets Presentation Contents What are CSS? What are CSS? History of CSS History of CSS.
Today’s objectives  Review  CSS | Rules | Declarations  HTML Structure document  Class asignment.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 7.
IS 360 Declaring CSS Styles. Slide 2 Introduction Learn about the three ways to declare a style Inline / embedded / external Learn about the effect of.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
Cascading Style Sheets Robin Burke ECT 270. Outline Midterm The Layout Debate CSS properties Fonts Alignment Color CSS selection selectors pseudo-classes.
ECA225 Applied Interactive Programming Cascading Style Sheets, pt 1 ECA 225 Applied Online Programming.
INTRODUCTORY Tutorial 3 Using CSS to Format Multiple Pages.
>> More on CSS Selectors. Pre-requisite Open the file called sample.txt Copy the all the text from the file Open your browser and go to codepen.io Paste.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
1 Web Development CSS (Cascading Style Sheet). 2 1.Setting rules for multiple elements To decrease the amount of typing for setting rules for multiple.
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
Tutorial 4 Creating Special Effects with CSS. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Work with CSS selectors.
Tutorial 4 Creating Special Effects with CSS. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Work with CSS selectors.
Relative, absolute, and Floating Positioning, Cascading Style Sheet, and Inheritance.
CSS: Cascading Style Sheets Part II. Style Syntax.
CH 12 CSS Style Sheets 1. Objective What is CSS? Selecting elements Different rules for different media Importing style sheets 2.
ECA 228 Internet/Intranet Design I Cascading Style Sheets.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, Third Edition.
HTML 5 AND CSS Dr Mohd Soperi Mohd Zahid Semester /16.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
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.
Cascading Style Sheets Robin Burke ECT 270. Outline CSS properties Fonts Alignment Color CSS selection selectors.
IS 360 Understanding CSS Selectors. Slide 2 Types of Selectors There are different types of selectors Each has a different level of “specificity” An element.
Internet & World Wide Web How to Program, 5/e 1. 2.
Working with Cascading Style Sheets
>> CSS Rules Selection
IS 360 Understanding CSS Selectors
Chapter 6 Introducing Cascading Style Sheets
Presentation transcript:

Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition

6-2 Objectives Understand CSS style rules Build a basic style sheet Understand the cascade and inheritance Use basic selection techniques Use advanced selection techniques Work with the and elements Use pseudo-classes and pseudo-selectors

Principles of Web Design, 4th Edition6-3 Understanding CSS Style Rules

Principles of Web Design, 4th Edition6-4 Understanding CSS Style Rules In CSS, style rules express the style characteristics for an HTML element A set of style rules is called a style sheet Style rules are easy to write and interpret

Principles of Web Design, 4th Edition6-5 Understanding CSS Style Rules (continued) Style rules are composed of two parts: a selector and a declaration The selector determines the element to which the rule is applied The declaration details the exact property values

Principles of Web Design, 4th Edition6-6

Principles of Web Design, 4th Edition6-7 Understanding CSS Style Rules (continued) The declaration contains a property and a value The property is a quality or characteristic The precise specification of the property is contained in the value CSS includes a wide variety of different properties, each with a specific number of values

Principles of Web Design, 4th Edition6-8

Principles of Web Design, 4th Edition6-9 Combining CSS Rules with HTML Three ways to combine CSS rules and HTML –The style attribute –The element –External style sheet

Principles of Web Design, 4th Edition6-10 The style attribute –Defines a style for a single element –Generally used to override a style set at a higher level in the document for a single element –Only affects one instance of an element in a document Combining CSS Rules with HTML (continued)

Principles of Web Design, 4th Edition6-11 The element –Always contained in the section of the document –Generally used to override a style set at a higher level in the document for a single document –Only affects the document in which it resides Combining CSS Rules with HTML (continued)

Principles of Web Design, 4th Edition6-12 Combining CSS Rules with HTML (continued) External style sheet –Text document that contains style rules –Allows specification of rules for multiple HTML documents –Does not contain HTML code

Principles of Web Design, 4th Edition6-13 Combining CSS Rules with HTML (continued) Linking to an external style sheet – element establishes document relationships –Can only be used in the section of a document –Tells the browser where to find the external style sheet

Principles of Web Design, 4th Edition6-14 Combining CSS Rules with HTML (continued) Combining multiple style sheets keyword Allows import of style rules from other style sheets Must precede all rules in style sheet or they will be ignored by the browser –Style rules contained within document take precedence over imported style rules –Weight of imported style sheets based on import order

Principles of Web Design, 4th Edition6-15 Building a Basic Style Sheet

Principles of Web Design, 4th Edition6-16

Principles of Web Design, 4th Edition6-17

Principles of Web Design, 4th Edition6-18 Understanding the Cascade

Principles of Web Design, 4th Edition6-19 Understanding the Cascade Cascading mechanism of CSS determines which rules are assigned to document elements by assigning a weight based on four variables: –Origin of the rule –Specificity of the selector –Order of the rule in the style sheet –Use of the !important keyword

Principles of Web Design, 4th Edition6-20 Determining Rule Weight by Origin Cascading order of precedence: –Rules from author’s style sheet –Rules from user’s style sheet –Rules from browser’s style sheet

Principles of Web Design, 4th Edition6-21

Principles of Web Design, 4th Edition6-22 Determining Rule Weight By Specificity Rules with more specific selectors take precedence over rules with less specific selectors

Principles of Web Design, 4th Edition6-23 Determining Rule Weight By Order Based on order of rule within style sheet –Those listed later take precedence over those listed earlier in the style sheet

Principles of Web Design, 4th Edition6-24 Determining Rule Weight with the !Important Keyword Allows user to override author’s style setting for a particular element Improves accessibility of documents –Gives control to users with special requirements

Principles of Web Design, 4th Edition6-25 Understanding Inheritance

Principles of Web Design, 4th Edition6-26 Understanding Inheritance Based on hierarchical structure of documents –CSS rules inherit from parent elements to child elements: Thus elements will inherit style rules from elements unless a style rule is specifically set for the element

Principles of Web Design, 4th Edition6-27

Principles of Web Design, 4th Edition6-28 Understanding Basic Selection Techniques

Principles of Web Design, 4th Edition6-29 Understanding Basic Selection Techniques Using type selectors Grouping selectors Combining declarations Using descendant selectors

Principles of Web Design, 4th Edition6-30 Using Type Selectors The following rule selects the H1 element:

Principles of Web Design, 4th Edition6-31 Grouping Selectors The following rule selects the H1 and H2 elements: h1, h2 {color: green;}

Principles of Web Design, 4th Edition6-32 Combining Declarations The following style rules set the element to 12-point blue text: p {color: blue;} p {font-size: 12pt;} These two style rules can be expressed in a simpler way: p {color: blue; font-size: 12pt;}

Principles of Web Design, 4th Edition6-33 Using Descendant Selectors A descendant selector lets you specify the exact context in which a style is applied To specify that elements appear blue only within elements, use the following rule: p b {color: blue;}

Principles of Web Design, 4th Edition6-34 Understanding Advanced Selection Techniques

Principles of Web Design, 4th Edition6-35 Understanding Advanced Selection Techniques The class attribute The id attribute The and elements The pseudo-class and pseudo-element selectors The universal selector

Principles of Web Design, 4th Edition6-36 Using the Class Attribute Selector The class attribute lets you write rules and then apply them to groups of elements that you have classified To create a class, declare it within the element first –The period (.) flag character indicates that the selector is a class selector

Principles of Web Design, 4th Edition6-37 Using the Class Attribute Selector (continued)

Principles of Web Design, 4th Edition6-38 Using the Class Attribute Selector (continued) This is the first paragraph of the document. It has a different style based on the “special” class selector.

Principles of Web Design, 4th Edition6-39 Using the id Attribute Selector The difference between id and class is that id refers to only one instance of the id attribute value within a document

Principles of Web Design, 4th Edition6-40

Principles of Web Design, 4th Edition6-41 Working with The element lets you specify logical divisions within a document that have their own name and style properties is a block-level element; it contains a leading and trailing carriage return You can use with the class attribute to create customized block-level elements

Principles of Web Design, 4th Edition6-42 Working with (continued) To create a division, declare it within the element first The following example specifies a division named column as the selector for the rule: div.column {width: 200px; height: auto; padding: 15px; border: thin solid;}

Principles of Web Design, 4th Edition6-43 Working with (continued) Next, specify the element in the document; then use the class attribute to specify the exact type of division In the following example, the code defines the element as the special class named “introduction” This division displays as a column of text in the browser window.

Principles of Web Design, 4th Edition6-44

Principles of Web Design, 4th Edition6-45 Working with The element lets you specify inline elements within a document that have their own name and style properties Inline elements go within the line of text, like the element

Principles of Web Design, 4th Edition6-46 Working with (continued) To create a span, declare it within the element first The following example specifies a element named “logo” as the selector for the rule: span.logo {color:red;}

Principles of Web Design, 4th Edition6-47 Working with (continued) Next, specify the element in the document; then use the class attribute to specify the exact type of span In the following example, the code defines the element as the special class named “logo” Welcome to the Wonder Software Web site.

Principles of Web Design, 4th Edition6-48 Working with (continued)

Principles of Web Design, 4th Edition6-49 Using the Link Pseudo-Classes The :link and :visited pseudo-classes let you change the style characteristics for new, unvisited links (:link) and visited links (:visited) These pseudo-classes only apply to the element with an href attribute

Principles of Web Design, 4th Edition6-50 Using the Link Pseudo-Classes (continued) The following rules change the colors of the hypertext links: :link {color: red;} :visited {color: green;}

Principles of Web Design, 4th Edition6-51 Using the hover Pseudo-Class The :hover pseudo-class lets you apply a style that appears when the user points to an element with a pointing device This is a useful navigation aid to add to the element, with the result that the link appears highlighted when the user points to it with the mouse

Principles of Web Design, 4th Edition6-52 a:hover {background-color: yellow;}

Principles of Web Design, 4th Edition6-53 Using the :first-letter Pseudo- Element Use the :first-letter pseudo-element to apply style rules to the first letter of any element: p:first-letter {font-weight: bold; font-size: 200%;}

Principles of Web Design, 4th Edition6-54

Principles of Web Design, 4th Edition6-55 Using the :first-letter Pseudo- Element (continued) You can make the initial capital a drop capital by adding the float property to the rule, which allows the letter to extend downward: p.dropcap:first-letter {font-weight: bold; font-size: 200%; float: left;}

Principles of Web Design, 4th Edition6-56

Principles of Web Design, 4th Edition6-57 Using the :first-line Pseudo- Element The :first-line pseudo-element works in much the same way as :first-letter, except for the obvious difference that it affects the first line of text in an element: p.introduction:first-line {text-transform: uppercase;}

Principles of Web Design, 4th Edition6-58

Principles of Web Design, 4th Edition6-59 Using the Universal Selector The universal selector lets you quickly select groups of elements and apply a style rule You can also use the universal selector to select all children of an element * {color: purple;} div * {font-family: sans-serif;}

Principles of Web Design, 4th Edition6-60 Summary CSS rules can be combined with your HTML code in a number of ways CSS rules are easy to write and read CSS uses cascading and inheritance to determine which style rules take precedence –The !important declaration lets users override the author’s style rules

Principles of Web Design, 4th Edition6-61 Summary (continued) Basic style rules let you apply style rules based on standard element selectors –You can combine the selectors and declarations to create more powerful style expressions –You can also select elements based on the contextual relationship of elements in the document tree

Principles of Web Design, 4th Edition6-62 Summary (continued) The advanced selection techniques allow you to use the class attribute selector, which is often paired with the and HTML elements –These elements have no style of their own, but offer a convenient way of expressing style for any section of a document, whether block-level or inline –Additionally, class allows you to choose a meaningful naming convention for your style rules

Principles of Web Design, 4th Edition6-63 Summary (continued) The pseudo-class and pseudo-element selectors let you change the color and styling of hypertext links and the effect elements of a document, such as first line and first letter, that are not signified with the standard HTML elements