SlideShare a Scribd company logo
1 of 58
Principles of Web Design
5th Edition
Chapter Four
Cascading Style Sheets
Objectives
When you complete this chapter, you will be able to:
• Recognize the benefits of using CSS
• Build a basic style sheet
• Use inheritance to write simpler style rules
• Examine basic selection techniques
• Apply basic selection techniques
• Use class and id selectors
• Use the <div> and <span> elements
• Use other selectors
2
Recognizing the Benefits of
Using CSS
3
The Evolution of CSS
• CSS was developed to standardize display
information
• CSS was slow to be supported by browsers
• Newer browsers offer more complete support
• Latest release is CSS3
• CSS3 is not yet evenly supported
Principles of Web Design 5th Ed. 4
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 5th Ed. 5
CSS Style Rules
• 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 5th Ed. 6
Principles of Web Design 5th Ed. 7
CSS Style Rules
• 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 5th Ed. 8
Principles of Web Design 5th Ed. 9
Combining CSS Style Rules with
HTML
You combine CSS with HTML in three ways:
• Inline style
• Internal style sheet
• External style sheet
Principles of Web Design 5th Ed. 10
Principles of Web Design 5th Ed. 11
Using External Style Sheets
• External style sheets let you specify rules for
multiple Web pages
• These are text documents that contain style rules
• External style sheets have a .css extension
Principles of Web Design 5th Ed. 12
Linking to an External Style Sheet
• The link element lets you specify an external style
sheet
• It is used within the <head> section of a document
<head>
<title>Sample Document</title>
<link href="styles.css"
rel="stylesheet" type="text/css" />
</head>
Principles of Web Design 5th Ed. 13
Using Internal Style Sheets
• Internal style sheets are contained within the
<style> element
• The style element is contained within the <head>
section of the document
• Style rules contained in an internal style sheet only
affect the document in which they reside
<head>
<title>Sample Document</title>
<style type="text/css">
h1 {color: red;}
</style>
</head>
Principles of Web Design 5th Ed. 14
Using Inline Styles
• You can define styles for a single element with the
style attribute
• The style attribute can be used to override a style
that was set at a higher level
• The style attribute is useful for testing styles during
development
• This is the least used method of applying CSS
styles
• <h1 style="color: blue">Some Text</h1>
Principles of Web Design 5th Ed. 15
Writing Clean CSS Code
• Write CSS code that is consistent and easy to read
• Correct but hard-to-read:
p {font-family: arial, helvetica, sans-serif; font-
size: 85%; line-height: 110%; margin-left: 30px;}
• Better:
p {
font-family: arial, helvetica, sans-serif;
font-size: 85%;
line-height: 110%;
margin-left: 30px;
}
• Use comments in your code
Principles of Web Design 5th Ed. 16
Using Inheritance to Write Simpler
Style Rules
• Elements in an HTML document are structured in a
hierarchy
• Parent elements contain child elements
• Elements can be both parent and child elements
• The CSS properties inherit from parent to child
• The property descriptions list whether a property is
inherited
• You can style multiple document elements with just
a few style rules using inheritance
Principles of Web Design 5th Ed. 17
Principles of Web Design 5th Ed. 18
Using Inheritance to Write Simpler
Style Rules
• Specific style rules:
<style type="text/css">
h1 {color: red;}
p {color: red;}
ul {color: red;}
em {color: red;}
li {color: red;}
</style>
• Using inheritance:
<style type="text/css">
body {color: red;}
</style>
Principles of Web Design 5th Ed. 19
Examining Basic Selection
Techniques
• In this section, you will review style rule syntax and
learn about the following basic selection
techniques:
– Using type selectors
– Grouping selectors
– Combining declarations
– Using descendant selectors
Principles of Web Design 5th Ed. 20
Using Type Selectors
• The selector determines the element to which a
style declaration is applied
• Type selectors are the simplest form of selector
• They select every element in the document that
matches the style rule
• In the following example, all h1 elements are red
Principles of Web Design 5th Ed. 21
Principles of Web Design 5th Ed. 22
Grouping Selectors
• You can group selectors to which the same rules
apply
• Specific style rules:
h1 {color: red;}
h2 {color: red;}
• Grouping selectors:
h1, h2 {color: red;}
Principles of Web Design 5th Ed. 23
Combining Declarations
• You can state multiple property declarations for the
same selector
• Specific style rules:
p {color: blue;}
p {font-size: 125%;}
• Combining declarations:
p {
color: blue;
font-size: 125%;
}
Principles of Web Design 5th Ed. 24
Using Descendant Selectors
• You can select elements that are descendents of
other elements
• Selecting only <em> elements that are contained
within <p> elements
p em {color: blue;}
Principles of Web Design 5th Ed. 25
Using the Universal Selector
• Universal selector lets you select groups of
elements
• Selecting all children of the dead element:
div * {font-family: sans-serif;}
Principles of Web Design 5th Ed. 26
Using Class and ID Selectors
• You will learn to select elements of an HTML
document using the following methods:
– The class selector
– The id selector
– The <div> and <span> elements
– The pseudo-class and pseudo-element selectors
Principles of Web Design 5th Ed. 27
Using the Class Selector
• The class selector lets you write rules and give
them a name
• You can apply that name to any element you
choose
• The class attribute lets you apply the style rule
name to an element
• The period (.) flag character indicates the selector
is a class selector
Principles of Web Design 5th Ed. 28
Principles of Web Design 5th Ed. 29
Using the Class Selector
• Style rule:
.intro {font-size: 125%; font-family:
sans-serif;}
• Applied in document:
<p class="intro">This is the first
paragraph of thedocument. It has a
different style based on the
"intro”class selector.</p>
Principles of Web Design 5th Ed. 30
Principles of Web Design 5th Ed. 31
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
• The ID attribute is used to identify layout sections of the
page
• The ID attribute uses a pound sign (#) flag character
Principles of Web Design 5th Ed. 32
Principles of Web Design 5th Ed. 33
Using the id Attribute Selector
• Style rule:
<p id="copyright">This is the copyright
information for the page.</p>
• Applied in document:
<p class="intro">This is the first paragraph of
the document. It has a different style based on
the "intro” class selector.</p>
Principles of Web Design 5th Ed. 34
Using the <div> and <span>
Elements
• The <div> (division) and <span> (span of words)
elements are designed to be used with CSS
• They let you specify logical divisions within a
document that have their own name and style
properties
Principles of Web Design 5th Ed. 35
Working with <div> elements
• Use <div> with the class and ID attributes to create
logical divisions on a Web page
• A division with an id named column as the selector:
div#column {
width: 200px;
height: auto;
padding: 15px;
border: thin solid;
}
Applied in the document:
<div id="column">This division displays… </div>
Principles of Web Design 5th Ed. 36
Working with Span Elements
• The span element lets you specify in-line elements
that have their own name and style properties
• In-line elements reside within a line of text
Principles of Web Design 5th Ed. 37
Working with Span Elements
• Style rule:
span.logo {
color: white;
background-color: black;
}
• Applied in document:
<p>Welcome to the <span class="logo">Wonder
Software</span>Web site.</p>
Principles of Web Design 5th Ed. 38
Principles of Web Design 5th Ed. 39
Using Attribute Selectors
• Attribute selectors let you select an element based
on whether the element contains an attribute
• Elements can be selected based on a specific
value the attribute contains
Principles of Web Design 5th Ed. 40
Using Attribute Selectors
• Attribute selectors match against attributes and
their values
• To select this element:
<img src="images/home.gif" title="home"
alt="Home navigation button" />
using attribute selectors, you could use the value
that the title attribute contains, as shown:
img[title=home] {border-color: red;}
Principles of Web Design 5th Ed. 41
Using Pseudo-Class and Pseudo-
Element Selectors
• Pseudo-classes select elements based on
characteristics other than their element name
• For example, you can change the characteristics of
hypertext links with pseudo-classes
• Pseudo-elements let you change other aspects of a
document that are not classified by standard
elements such as the first letter or line of a
paragraph
Principles of Web Design 5th Ed. 42
Principles of Web Design, 4th
Edition
6-43
Using the Link Pseudo-Classes
• The link pseudo-classes let you change the style
characteristics for four different hypertext link
states
• These pseudo-classes only apply to the <a>
element with an href attribute
Principles of Web Design 5th Ed. 44
Using the Link Pseudo-Classes
• Because of the specificity of the pseudo-class
selectors, you should always place your link
pseudo-class in the following order:
1. Link
2. Visited
3. Hover
4. Active
Principles of Web Design 5th Ed. 45
Principles of Web Design, 4th
Edition
6-46
Using the Link Pseudo-Classes
• The following rules change the colors of the
hypertext links:
:link {color: red;}
:visited {color: green;}
Principles of Web Design, 4th
Edition
6-47
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
a:hover {background-color: yellow;}
Principles of Web Design, 4th
Edition
6-48
Principles of Web Design, 4th
Edition
6-49
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
Edition
6-50
Principles of Web Design, 4th
Edition
6-51
Using the :first-line Pseudo-Element
• The :first-line pseudo-element works in much the
same way as :first-letter
• It affects the first line of text in an element:
p:first-line {text-transform:
uppercase;}
Principles of Web Design, 4th Edition
6-52
Understanding How the Cascade
Affects Style Rules
• To cascade means that multiple style sheets and
style rules can apply to the same document
• Only one rule can apply to an element
• The CSS cascading mechanism determines which
rules apply based on three variables:
– Specificity of the selector
– Order of the rule in the style sheet
– Use of the !important keyword
Principles of Web Design 5th Ed. 53
CSS3 Selectors
Principles of Web Design 5th Ed. 54
Principles of Web Design 5th Ed. 55
Principles of Web Design 5th Ed. 56
Summary
• CSS rules can be combined with the HTML code in
a number of ways
• CSS is easy to read and write
• CSS uses inheritance and cascading to determine
which style rules take precedence
• You can combine selectors and declarations in
multiple ways
• There are many ways to select elements
Principles of Web Design 5th Ed. 57
Summary
• Class and ID attribute selectors are often paired
with <div> and <span> elements to create layout
elements
• The pseudo-class and pseudo-element selectors
let you change color and styling of links and other
elements of a document
Principles of Web Design 5th Ed. 58

More Related Content

Similar to 9781111528705_PPT_ch04.ppt

Code &amp; design your first website (3:16)
Code &amp; design your first website (3:16)Code &amp; design your first website (3:16)
Code &amp; design your first website (3:16)
Thinkful
 
Castro Chapter 8
Castro Chapter 8Castro Chapter 8
Castro Chapter 8
Jeff Byrnes
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2
Sónia
 

Similar to 9781111528705_PPT_ch04.ppt (20)

Ppt ch01
Ppt ch01Ppt ch01
Ppt ch01
 
Web Development - Lecture 5
Web Development - Lecture 5Web Development - Lecture 5
Web Development - Lecture 5
 
HTML & CSS: Chapter 04
HTML & CSS: Chapter 04HTML & CSS: Chapter 04
HTML & CSS: Chapter 04
 
Css
CssCss
Css
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
Html,CSS & UI/UX design
Html,CSS & UI/UX designHtml,CSS & UI/UX design
Html,CSS & UI/UX design
 
Css
CssCss
Css
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Web Concepts_Introduction to presentation.pptx
Web Concepts_Introduction to presentation.pptxWeb Concepts_Introduction to presentation.pptx
Web Concepts_Introduction to presentation.pptx
 
BITM3730 9-19.pptx
BITM3730 9-19.pptxBITM3730 9-19.pptx
BITM3730 9-19.pptx
 
basic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdfbasic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdf
 
BITM3730 9-20.pptx
BITM3730 9-20.pptxBITM3730 9-20.pptx
BITM3730 9-20.pptx
 
BITM3730Week4.pptx
BITM3730Week4.pptxBITM3730Week4.pptx
BITM3730Week4.pptx
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Code &amp; design your first website (3:16)
Code &amp; design your first website (3:16)Code &amp; design your first website (3:16)
Code &amp; design your first website (3:16)
 
Cascading style sheet an introduction
Cascading style sheet   an introductionCascading style sheet   an introduction
Cascading style sheet an introduction
 
Castro Chapter 8
Castro Chapter 8Castro Chapter 8
Castro Chapter 8
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
The Anatomy of a WordPress File
The Anatomy of a WordPress FileThe Anatomy of a WordPress File
The Anatomy of a WordPress File
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2
 

More from SimonChirambira (7)

9781111528705_PPT_ch03.ppt
9781111528705_PPT_ch03.ppt9781111528705_PPT_ch03.ppt
9781111528705_PPT_ch03.ppt
 
9781111528705_PPT_ch07.ppt
9781111528705_PPT_ch07.ppt9781111528705_PPT_ch07.ppt
9781111528705_PPT_ch07.ppt
 
9781111528705_PPT_ch09.ppt
9781111528705_PPT_ch09.ppt9781111528705_PPT_ch09.ppt
9781111528705_PPT_ch09.ppt
 
9781111528705_PPT_ch11.ppt
9781111528705_PPT_ch11.ppt9781111528705_PPT_ch11.ppt
9781111528705_PPT_ch11.ppt
 
9781111528705_PPT_ch08.ppt
9781111528705_PPT_ch08.ppt9781111528705_PPT_ch08.ppt
9781111528705_PPT_ch08.ppt
 
9781111528705_PPT_ch05.ppt
9781111528705_PPT_ch05.ppt9781111528705_PPT_ch05.ppt
9781111528705_PPT_ch05.ppt
 
9781111528705_PPT_ch10.ppt
9781111528705_PPT_ch10.ppt9781111528705_PPT_ch10.ppt
9781111528705_PPT_ch10.ppt
 

Recently uploaded

Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...
Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...
Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...
HyderabadDolls
 
9352852248 Call Girls Naroda Escort Service Available 24×7 In Naroda
9352852248 Call Girls  Naroda Escort Service Available 24×7 In Naroda9352852248 Call Girls  Naroda Escort Service Available 24×7 In Naroda
9352852248 Call Girls Naroda Escort Service Available 24×7 In Naroda
gargpaaro
 
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
eeanqy
 
Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...
gajnagarg
 
Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...
nirzagarg
 
In Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in Riyadh
In Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in RiyadhIn Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in Riyadh
In Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in Riyadh
ahmedjiabur940
 
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
nirzagarg
 
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
wpkuukw
 
Design-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora AgencyDesign-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora Agency
Isadora Agency
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
ehyxf
 

Recently uploaded (20)

TRose UXPA Experience Design Concord .pptx
TRose UXPA Experience Design Concord .pptxTRose UXPA Experience Design Concord .pptx
TRose UXPA Experience Design Concord .pptx
 
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
 
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
 
Spring Summer 26 Colors Trend Book Peclers Paris
Spring Summer 26 Colors Trend Book Peclers ParisSpring Summer 26 Colors Trend Book Peclers Paris
Spring Summer 26 Colors Trend Book Peclers Paris
 
Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...
Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...
Salkhia @ Cheap Call Girls In Kolkata | Book 8005736733 Extreme Naughty Call ...
 
9352852248 Call Girls Naroda Escort Service Available 24×7 In Naroda
9352852248 Call Girls  Naroda Escort Service Available 24×7 In Naroda9352852248 Call Girls  Naroda Escort Service Available 24×7 In Naroda
9352852248 Call Girls Naroda Escort Service Available 24×7 In Naroda
 
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
 
Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Mysore [ 7014168258 ] Call Me For Genuine Models We...
 
Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Moradabad [ 7014168258 ] Call Me For Genuine Models...
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...
❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...
❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...
 
In Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in Riyadh
In Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in RiyadhIn Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in Riyadh
In Saudi Arabia Jeddah (+918761049707)) Buy Abortion Pills For Sale in Riyadh
 
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
Top profile Call Girls In Mau [ 7014168258 ] Call Me For Genuine Models We ar...
 
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
 
Essential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive GuideEssential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive Guide
 
👉 Itanagar Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Itanagar Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...👉 Itanagar Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Itanagar Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
 
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
 
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
 
Design-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora AgencyDesign-System - FinTech - Isadora Agency
Design-System - FinTech - Isadora Agency
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
 

9781111528705_PPT_ch04.ppt

  • 1. Principles of Web Design 5th Edition Chapter Four Cascading Style Sheets
  • 2. Objectives When you complete this chapter, you will be able to: • Recognize the benefits of using CSS • Build a basic style sheet • Use inheritance to write simpler style rules • Examine basic selection techniques • Apply basic selection techniques • Use class and id selectors • Use the <div> and <span> elements • Use other selectors 2
  • 3. Recognizing the Benefits of Using CSS 3
  • 4. The Evolution of CSS • CSS was developed to standardize display information • CSS was slow to be supported by browsers • Newer browsers offer more complete support • Latest release is CSS3 • CSS3 is not yet evenly supported Principles of Web Design 5th Ed. 4
  • 5. 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 5th Ed. 5
  • 6. CSS Style Rules • 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 5th Ed. 6
  • 7. Principles of Web Design 5th Ed. 7
  • 8. CSS Style Rules • 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 5th Ed. 8
  • 9. Principles of Web Design 5th Ed. 9
  • 10. Combining CSS Style Rules with HTML You combine CSS with HTML in three ways: • Inline style • Internal style sheet • External style sheet Principles of Web Design 5th Ed. 10
  • 11. Principles of Web Design 5th Ed. 11
  • 12. Using External Style Sheets • External style sheets let you specify rules for multiple Web pages • These are text documents that contain style rules • External style sheets have a .css extension Principles of Web Design 5th Ed. 12
  • 13. Linking to an External Style Sheet • The link element lets you specify an external style sheet • It is used within the <head> section of a document <head> <title>Sample Document</title> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> Principles of Web Design 5th Ed. 13
  • 14. Using Internal Style Sheets • Internal style sheets are contained within the <style> element • The style element is contained within the <head> section of the document • Style rules contained in an internal style sheet only affect the document in which they reside <head> <title>Sample Document</title> <style type="text/css"> h1 {color: red;} </style> </head> Principles of Web Design 5th Ed. 14
  • 15. Using Inline Styles • You can define styles for a single element with the style attribute • The style attribute can be used to override a style that was set at a higher level • The style attribute is useful for testing styles during development • This is the least used method of applying CSS styles • <h1 style="color: blue">Some Text</h1> Principles of Web Design 5th Ed. 15
  • 16. Writing Clean CSS Code • Write CSS code that is consistent and easy to read • Correct but hard-to-read: p {font-family: arial, helvetica, sans-serif; font- size: 85%; line-height: 110%; margin-left: 30px;} • Better: p { font-family: arial, helvetica, sans-serif; font-size: 85%; line-height: 110%; margin-left: 30px; } • Use comments in your code Principles of Web Design 5th Ed. 16
  • 17. Using Inheritance to Write Simpler Style Rules • Elements in an HTML document are structured in a hierarchy • Parent elements contain child elements • Elements can be both parent and child elements • The CSS properties inherit from parent to child • The property descriptions list whether a property is inherited • You can style multiple document elements with just a few style rules using inheritance Principles of Web Design 5th Ed. 17
  • 18. Principles of Web Design 5th Ed. 18
  • 19. Using Inheritance to Write Simpler Style Rules • Specific style rules: <style type="text/css"> h1 {color: red;} p {color: red;} ul {color: red;} em {color: red;} li {color: red;} </style> • Using inheritance: <style type="text/css"> body {color: red;} </style> Principles of Web Design 5th Ed. 19
  • 20. Examining Basic Selection Techniques • In this section, you will review style rule syntax and learn about the following basic selection techniques: – Using type selectors – Grouping selectors – Combining declarations – Using descendant selectors Principles of Web Design 5th Ed. 20
  • 21. Using Type Selectors • The selector determines the element to which a style declaration is applied • Type selectors are the simplest form of selector • They select every element in the document that matches the style rule • In the following example, all h1 elements are red Principles of Web Design 5th Ed. 21
  • 22. Principles of Web Design 5th Ed. 22
  • 23. Grouping Selectors • You can group selectors to which the same rules apply • Specific style rules: h1 {color: red;} h2 {color: red;} • Grouping selectors: h1, h2 {color: red;} Principles of Web Design 5th Ed. 23
  • 24. Combining Declarations • You can state multiple property declarations for the same selector • Specific style rules: p {color: blue;} p {font-size: 125%;} • Combining declarations: p { color: blue; font-size: 125%; } Principles of Web Design 5th Ed. 24
  • 25. Using Descendant Selectors • You can select elements that are descendents of other elements • Selecting only <em> elements that are contained within <p> elements p em {color: blue;} Principles of Web Design 5th Ed. 25
  • 26. Using the Universal Selector • Universal selector lets you select groups of elements • Selecting all children of the dead element: div * {font-family: sans-serif;} Principles of Web Design 5th Ed. 26
  • 27. Using Class and ID Selectors • You will learn to select elements of an HTML document using the following methods: – The class selector – The id selector – The <div> and <span> elements – The pseudo-class and pseudo-element selectors Principles of Web Design 5th Ed. 27
  • 28. Using the Class Selector • The class selector lets you write rules and give them a name • You can apply that name to any element you choose • The class attribute lets you apply the style rule name to an element • The period (.) flag character indicates the selector is a class selector Principles of Web Design 5th Ed. 28
  • 29. Principles of Web Design 5th Ed. 29
  • 30. Using the Class Selector • Style rule: .intro {font-size: 125%; font-family: sans-serif;} • Applied in document: <p class="intro">This is the first paragraph of thedocument. It has a different style based on the "intro”class selector.</p> Principles of Web Design 5th Ed. 30
  • 31. Principles of Web Design 5th Ed. 31
  • 32. 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 • The ID attribute is used to identify layout sections of the page • The ID attribute uses a pound sign (#) flag character Principles of Web Design 5th Ed. 32
  • 33. Principles of Web Design 5th Ed. 33
  • 34. Using the id Attribute Selector • Style rule: <p id="copyright">This is the copyright information for the page.</p> • Applied in document: <p class="intro">This is the first paragraph of the document. It has a different style based on the "intro” class selector.</p> Principles of Web Design 5th Ed. 34
  • 35. Using the <div> and <span> Elements • The <div> (division) and <span> (span of words) elements are designed to be used with CSS • They let you specify logical divisions within a document that have their own name and style properties Principles of Web Design 5th Ed. 35
  • 36. Working with <div> elements • Use <div> with the class and ID attributes to create logical divisions on a Web page • A division with an id named column as the selector: div#column { width: 200px; height: auto; padding: 15px; border: thin solid; } Applied in the document: <div id="column">This division displays… </div> Principles of Web Design 5th Ed. 36
  • 37. Working with Span Elements • The span element lets you specify in-line elements that have their own name and style properties • In-line elements reside within a line of text Principles of Web Design 5th Ed. 37
  • 38. Working with Span Elements • Style rule: span.logo { color: white; background-color: black; } • Applied in document: <p>Welcome to the <span class="logo">Wonder Software</span>Web site.</p> Principles of Web Design 5th Ed. 38
  • 39. Principles of Web Design 5th Ed. 39
  • 40. Using Attribute Selectors • Attribute selectors let you select an element based on whether the element contains an attribute • Elements can be selected based on a specific value the attribute contains Principles of Web Design 5th Ed. 40
  • 41. Using Attribute Selectors • Attribute selectors match against attributes and their values • To select this element: <img src="images/home.gif" title="home" alt="Home navigation button" /> using attribute selectors, you could use the value that the title attribute contains, as shown: img[title=home] {border-color: red;} Principles of Web Design 5th Ed. 41
  • 42. Using Pseudo-Class and Pseudo- Element Selectors • Pseudo-classes select elements based on characteristics other than their element name • For example, you can change the characteristics of hypertext links with pseudo-classes • Pseudo-elements let you change other aspects of a document that are not classified by standard elements such as the first letter or line of a paragraph Principles of Web Design 5th Ed. 42
  • 43. Principles of Web Design, 4th Edition 6-43 Using the Link Pseudo-Classes • The link pseudo-classes let you change the style characteristics for four different hypertext link states • These pseudo-classes only apply to the <a> element with an href attribute
  • 44. Principles of Web Design 5th Ed. 44
  • 45. Using the Link Pseudo-Classes • Because of the specificity of the pseudo-class selectors, you should always place your link pseudo-class in the following order: 1. Link 2. Visited 3. Hover 4. Active Principles of Web Design 5th Ed. 45
  • 46. Principles of Web Design, 4th Edition 6-46 Using the Link Pseudo-Classes • The following rules change the colors of the hypertext links: :link {color: red;} :visited {color: green;}
  • 47. Principles of Web Design, 4th Edition 6-47 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 a:hover {background-color: yellow;}
  • 48. Principles of Web Design, 4th Edition 6-48
  • 49. Principles of Web Design, 4th Edition 6-49 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%; }
  • 50. Principles of Web Design, 4th Edition 6-50
  • 51. Principles of Web Design, 4th Edition 6-51 Using the :first-line Pseudo-Element • The :first-line pseudo-element works in much the same way as :first-letter • It affects the first line of text in an element: p:first-line {text-transform: uppercase;}
  • 52. Principles of Web Design, 4th Edition 6-52
  • 53. Understanding How the Cascade Affects Style Rules • To cascade means that multiple style sheets and style rules can apply to the same document • Only one rule can apply to an element • The CSS cascading mechanism determines which rules apply based on three variables: – Specificity of the selector – Order of the rule in the style sheet – Use of the !important keyword Principles of Web Design 5th Ed. 53
  • 54. CSS3 Selectors Principles of Web Design 5th Ed. 54
  • 55. Principles of Web Design 5th Ed. 55
  • 56. Principles of Web Design 5th Ed. 56
  • 57. Summary • CSS rules can be combined with the HTML code in a number of ways • CSS is easy to read and write • CSS uses inheritance and cascading to determine which style rules take precedence • You can combine selectors and declarations in multiple ways • There are many ways to select elements Principles of Web Design 5th Ed. 57
  • 58. Summary • Class and ID attribute selectors are often paired with <div> and <span> elements to create layout elements • The pseudo-class and pseudo-element selectors let you change color and styling of links and other elements of a document Principles of Web Design 5th Ed. 58