Chapter04 IntroductionToCSS 1
Chapter04 IntroductionToCSS 1
CSS
Chapter 4
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
What Is CSS?
Cascading Style Sheets (CSS)
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
What Is CSS?
Benefits of CSS
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
What Is CSS?
CSS Versions
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
What Is CSS?
Browser Adoption
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Overview
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Overview
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Selectors
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Properties
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Properties
Text letter-spacing
line-height
text-align
text-decoration*
text-indent
Borders border*
border-color
border-width
border-style
border-top, border-left, ...*
border-image*
border-radius
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Properties
Property Type Property
Spacing padding
padding-bottom, padding-left, ...
margin
margin-bottom, margin-left, ...
Sizing height
max-height
max-width
min-height
min-width
width
Lists list-style*
list-style-image
list-style-type
Effects animation*
filter
perspective
transform*
transition*
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Values
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Colors
• Name
• RGB
• Hexadecimal
• RGBa
• HSL
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Syntax
Relative and absolute Units
• Relative
• px
• em
• %
• vw,vh
• Absolute
• In
• cm
• Pt
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Location of Styles
Inline Styles
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Location of Styles
Embedded Style Sheet
Embedded style sheets (also called internal styles) are style rules placed
within the <style> element (inside the <head> element of an HTML
document).
<head>
<meta charset="utf-8">
<title>Share Your Travels -- New York - Central Park</title>
<style>
h1 { font-size: 24pt; }
h2 {
font-size: 18pt;
font-weight: bold;
}
</style>
</head>
<body>
...
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Location of Styles
External Style Sheet
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Location of Styles
External Style Sheet
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Remember the DOM tree
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Element Selectors
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Class Selectors
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Class Selectors
<head>
<title>Share Your Travels </title>
<style>
.first {
font-style: italic;
color: red;
}
</style>
</head>
<body>
<h1 class="first">Reviews</h1>
<div>
<p class="first">By Ricardo on <time>2016-05-23</time></p>
<p>Easy on the HDR buddy.</p>
</div>
<hr/>
<div>
<p class="first">By Susan on <time>2016-11-18</time></p>
<p>I love Central Park.</p>
</div>
<hr/>
</body>
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Id Selectors
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Id Selectors
<head>
<title>Share Your Travels </title>
<style>
#latestComment {
font-style: italic;
color: red;
}
</style>
</head>
<body>
<h1 class="first">Reviews</h1>
<div id="latestComment">
<p class="first">By Ricardo on <time>2016-05-23</time></p>
<p>Easy on the HDR buddy.</p>
</div>
<hr/>
<div>
<p class="first">By Susan on <time>2016-11-18</time></p>
<p>I love Central Park.</p>
</div>
<hr/>
</body>
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Attribute Selectors
[title] { … }
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Attribute Selectors
<head>
<meta charset="utf-8">
<title>Share Your Travels</title>
<style>
[title] {
cursor: help;
padding-bottom: 3px;
border-bottom: 2px dotted blue;
text-decoration: none;
}
</style>
</head>
<body>
<div>
<img src="images/flags/CA.png" title="Canada Flag" />
<h2><a href="countries.php?id=CA" title="see posts from Canada”> Canada</a></h2>
<p>Canada is a North American country consisting of … </p>
<div>
<img src="images/square/6114907897.jpg” title="At top of Sulphur Mountain" />
<img src="images/square/6592317633.jpg” title="Grace Presbyterian Church" />
<img src="images/square/6592914823.jpg” title="Calgary Downtown" />
</div>
</div>
</body>
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Attribute Selectors
Selector Matches
[] A specific attribute.
[=] A specific attribute with a specific value.
[~=] A specific attribute whose value matches
at least one of the words in a space delimited
list of words.
[^=] A specific attribute whose value begins
with a specified value.
[*=] A specific attribute whose value contains
a substring.
[$=] A specific attribute whose value ends
with a specified value.
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Pseudo-Element and Pseudo-Class Selectors
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Pseudo-Element and Pseudo-Class Selectors
• a:link
• a:visited
• :focus
• :hover
• :active
• :checked
• :first-child
• :first-letter
• :first-line
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Pseudo-Element and Pseudo-Class Selectors
<style>
a:link {
text-decoration: underline;
color: blue;
}
a:visited {
text-decoration: underline;
color: purple;
}
a:hover {
text-decoration: none;
font-weight: bold;
}
a:active {
background-color: yellow;
}
</style>
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Contextual Selectors
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Selectors
Contextual Selectors
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
CSS
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Inheritance
Many (but not all) CSS properties affect not only themselves but their descendants
as well.
Are inheritable:
• Font,
• color,
• list, and
• text properties
Not inheritable:
• layout,
• sizing,
• border,
• background, and
• spacing properties
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Inheritance
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Inheritance
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Specificity
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Specificity
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Specificity Algorithm
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Location
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How Styles Interact
Location
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How to Start with an Even
Playing Field
reset.css
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Cascade: How to Start with an Even
Playing Field
reset.css
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Overview
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Background
• Background
• Background-attachment
• Background-color
• Background-image
• Background-position
• Background-repeat
• Background-size
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Background
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Collapsing Margins
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
CSS TRBL Shortcut
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Box Dimensions
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Limitations of Height Property
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Overflow Property
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Box Sizing Using Percents
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
The Box Model
Inspecting CSS using modern browsers
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Text Styling
Font Family
Property Description
font A combined shorthand property that allows you to
set the family, style, size, variant, and weight in one
property.
style weight variant size font-family
font-family Specifies the typeface/font to use. More than one
can be specified.
font-size The size of the font in one of the measurement
units
font-style Specifies whether italic, oblique, or normal
font-variant Specifies either small-caps text or none
font-weight Specifies either normal, bold, bolder, lighter, or a
value between 100 and 900 in multiples of 100,
where larger number represents
weightier (i.e., bolder) text.
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Text Styling
Specifying the Font Family
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Text Styling
Different Font Families
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Text Styling
Font Sizes
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Text Styling
Font Face
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Text Styling
Paragraph Properties
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
CSS Text Styling
Just look at text-shadow
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Chapter 4
1 What Is CSS?
2 CSS Syntax
3 Location of
Styles 4 Selectors
5 6
The Cascade: How The Box Model
Styles Interact
7 8
CSS Text Styling Summary
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Summary
Key Terms
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Summary
Key Terms
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.
Questions
Randy Connolly and Ricardo Hoar Fundamentals of Web Development - 2nd Ed.