SlideShare a Scribd company logo
11
INTRODUCING CSS
OVERVIEW
• The benefits of CSS
• Understanding
document structure
• Writing style rules
• Attaching styles to
the HTML document
• Inheritance
• The cascade
• The box model
• CSS units of
measurement
The Benefits of CSS
• Precise type and layout control
• Less work: Change look of the whole site with one edit
• Accessibility: Markup stays semantic
• Flexibility: The same HTML markup can be made to appear
in dramatically different ways
Style Separate from Structure
These pages have the exact same HTML source but different
style sheets:
(csszengarden.com)
How Style Sheets Work
1. Start with a marked up document (like HTML, but could be
another XML markup language).
2. Write styles for how you want elements to look using CSS
syntax.
3. Attach the styles to the document (there are a number of
ways).
4. The browser uses your instructions when rendering the
elements.
Style Rules
Each rule selects an element and declares how it should display.
h1 { color: green; }
This rule selects all h1 elements and declares that they should
be green.
strong { color: red; font-style: italic; }
This rule selects all strong inline elements and declares that
they should be red and in an italic font.
Style Rule Structure
• A style rule is made up of a selector a declaration.
• The declaration is one or more property / value pairs.
Selectors
There are many types of selectors. Here are just two examples:
p {property: value;}
Element type selector: Selects all elements of this type (p) in the
document.
#intro {property: value}
ID selector (indicated by the # symbol) selects by ID value. In the
example, an element with an id of “intro” would be selected.
Declarations
The declaration is made up of a property/value pair contained
in curly brackets { }:
selector { property: value; }
Example
h2 { color: red;
font-size: 2em;
margin-left: 30px;
opacity: .5;
}
Declarations (cont’d)
• End each declaration with a semicolon to keep it separate from the
next declaration.
• White space is ignored, so you can stack declarations to make
them easier to read.
• Properties are defined in the CSS specifications.
• Values are dependent on the type of property:
• Measurements
• Keywords
• Color values
• More
CSS Comments
/* comment goes here */
• Content between /* and */ will be ignored by the browser.
• Useful for leaving notes or section labels in the style sheet.
• Can be used within rules to temporarily hide style declarations
in the design process.
Adding Styles to the Document
There are three ways to attach a style sheet to a document:
External style sheets
A separate, text-only .css file associated with the document with the
link element or @import rule
Embedded style sheets
Styles are listed in the head of the HTML document in the style
element.
Inline styles
Properties and values are added to an individual element with the
style attribute.
External Style Sheets
The style rules are saved in a separate text-only .css file and
attached via link or @import.
Via link element in HTML:
<head>
<title>Titles are require</title>
<link rel="stylesheet" href="/path/example.css">
</head>
Via @import rule in a style sheet:
<head>
<title>Titles are required</title>
<style>
@import url("/path/example.css");
p {font-face: Verdana;}
</style>
</head>
Embedded Style Sheets
Embedded style sheets are placed in the head of the document
via the style element:
<head>
<title>Titles are required</title>
<style>
/* style rules go here */
</style>
</head>
Inline Styles
Apply a style declaration to a single element with the style
attribute:
<p style="font-size: large;">Paragraph text...</p>
To add multiple properties, separate them with semicolons:
<h3 style="color: red; margin-top: 30px;">Intro</h3>
Document Structure
Documents have an implicit structure.
We give certain relationships names, as if they’re a family:
• All the elements contained in a given element are its
descendents.
• An element that is directly contained within another
element is the child of that element.
• The containing element is the parent of the contained
element.
• Two elements with the same parent are siblings.
Inheritance
• Many properties applied to elements are passed down to the
elements they contain. This is called inheritance.
• For example, applying a sans-serif font to a p element causes
the em element it contains to be sans-serif as well:
Inheritance (cont’d)
• Some properties inherit; others do not.
Properties related to text usually inherit; properties related to
layout generally don’t.
• Styles explicitly applied to specific elements override inherited
styles.
• You’ll learn to use inheritance strategically to keep your style
rules simple.
The Cascade
• The cascade refers to the system for resolving conflicts when
several styles apply to the same element.
• Style information is passed down (it “cascades” down) until
overwritten by a style rule with more weight.
• Weight is considered based on:
• Priority of style rule source
• Specificity of the selector
• Rule order
The Cascade: Priority
Style rules from sources higher in this list override rules from
sources listed below them.
• Any style marked as !important by the user (to accommodate
potential accessibility settings)
• Any style marked !important by the author (of the web page)
• Author styles (style sheets created in web site production)
• User styles (added by the reader)
• User agent styles (browser defaults)
The Cascade: Specificity
• When two rules in a single style sheet conflict, the type of
selector is used to determine which rule has more weight.
• For example, ID selectors are more specific than general
element selectors.
NOTE: Specificity will be discussed once we have covered more
selector types.
The Cascade: Rule Order
• When two rules have equal weight, rule order is used.
Whichever rule appears last “wins.”
<style>
p {color: red;}
p {color: blue;}
p {color: green;}
</style>
In this example, paragraphs would be green.
• Styles may come in from external style sheets, embedded
style rules, and inline styles. The style rule that gets parsed
last (the one closest to the content) will apply.
The Box Model
Browsers see every element on the page as being contained in a
little rectangular box. Block elements and inline elements
participate in the box model.
In this example, a blue border is added to all elements.
The Box Model (cont’d)
• The box model is the foundation of CSS page layout.
• Apply properties such as borders, margins, padding,
and backgrounds to element boxes.
• Position, move, grow, and shrink boxes to create fixed or
flexible page layouts.
CSS Units of Measurement
CSS provides a variety ways to specify measurements:
Absolute units
Have predefined meanings or real-world equivalents
Relative units
Based on the size of something else, such as the default text
size or the size of the parent element
Percentages
Calculated relative to another value, such as the size of the
parent element
Absolute Units
With the exception of pixels, absolute units are not appropriate
for web design:
px pixel
in inches
mm millimeters
cm centimeters
q 1/4 millimeter
pt points (1/72 inch)
pc pica (1 pica = 12 points = 1/6 inch)
Relative Units
Relative units are based on the size of something else:
em a unit equal to the current font size
ex x-height, equal to the height of a lowercase x
rem root em, equal to the font size of the html element
ch zero width, equal to the width of a zero (0)
vw viewport width unit (equal to 1/100 of viewport width)
vh viewport height unit (1/100 of viewport height)
vmin viewport minimum unit (value of vh or vw, whichever is smaller)
vmax viewport maximum unit (value of vh or vw, whichever is larger)
RELATIVE UNITS
The rem Unit
• The rem (root em) unit is based on the font size of the html
element, whatever that happens to be.
• Default in modern browsers: Root font size is 16 pixels, so a
rem = a 16-pixel unit.
• If the root font size of the document changes, so does the size
of a rem (and that’s good for keeping elements proportional).
RELATIVE UNITS
The em Unit
• The em unit is traditionally based on the width of a capital letter
M in the font.
• When the font size is 16 pixels,1em = 16 pixels, 2em = 32
pixels, and so on.
NOTE: Because they’re based on the font size of the current element, the
size of an em may not be consistent across a page.
RELATIVE UNITS
Viewport Percentage Lengths (vw/vh)
Viewport width (vw) and viewport height (vh) units are relative to
the size of the viewport (browser window):
vh = 1/100th width of viewport
vh = 1/100th height of viewport
They’re useful for making an element fill the viewport or a
specified percentage of it. This image will be 50% the width and
height of the viewport:
img { width: 50vw; height: 50vh; }
Browser Developer Tools
Major browsers have built-in tools that aid development:
• HTML, CSS, and JavaScript inspectors
• Network speed reports
• Animation tools
• Other helpful features
Browser Developer Tools (cont’d)
Chrome DevTools (View > Developer > Developer Tools)
Firefox, Safari, Opera, and Microsoft Edge also have developer tools.
Ad

More Related Content

What's hot (15)

Css
CssCss
Css
Vijay Raj Yanamala
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
Sun Technlogies
 
CSS - Basics
CSS - BasicsCSS - Basics
CSS - Basics
Shubham_Saurabh
 
CSS
CSSCSS
CSS
DivyaKS12
 
Border
BorderBorder
Border
Ankit Dubey
 
CSS Part I
CSS Part ICSS Part I
CSS Part I
Doncho Minkov
 
CSS Part II
CSS Part IICSS Part II
CSS Part II
Doncho Minkov
 
CSS
CSSCSS
CSS
ARJUN
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
Css1
Css1Css1
Css1
teach4uin
 
CSS Basics part One
CSS Basics part OneCSS Basics part One
CSS Basics part One
M Ashraful Islam Jewel
 
Introduction 2 css
Introduction 2 cssIntroduction 2 css
Introduction 2 css
Md Tarik Mahmud
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
Amit Tyagi
 
Cascstylesheets
CascstylesheetsCascstylesheets
Cascstylesheets
Digital Insights - Digital Marketing Agency
 
Css tutorial
Css tutorialCss tutorial
Css tutorial
Sohail Christoper
 

Similar to Chapter 11: Intro to CSS (20)

CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
RasheedMohammad6
 
Unit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology projectUnit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology project
abhiramhatwar
 
Cascading Style Sheets for web browser.pptx
Cascading Style Sheets for web browser.pptxCascading Style Sheets for web browser.pptx
Cascading Style Sheets for web browser.pptx
alvindalejoyosa1
 
DHTML
DHTMLDHTML
DHTML
Ravinder Kamboj
 
Css
CssCss
Css
Nasla C.K
 
CSS.pdf
CSS.pdfCSS.pdf
CSS.pdf
ssuseraa1a80
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
Singsys Pte Ltd
 
CSS Introduction
CSS Introduction CSS Introduction
CSS Introduction
Thapar Institute
 
Cascading style sheets, Introduction to web programming
Cascading style sheets, Introduction to web programmingCascading style sheets, Introduction to web programming
Cascading style sheets, Introduction to web programming
LikhithaBrunda
 
Css
CssCss
Css
Abhishek Kesharwani
 
Castro Chapter 7
Castro Chapter 7Castro Chapter 7
Castro Chapter 7
Jeff Byrnes
 
Css - Tutorial
Css - TutorialCss - Tutorial
Css - Tutorial
adelaticleanu
 
Web application is an application that is accessed by web visitor over intern...
Web application is an application that is accessed by web visitor over intern...Web application is an application that is accessed by web visitor over intern...
Web application is an application that is accessed by web visitor over intern...
MdAmreen
 
cascading style sheet in web design .ppt
cascading style sheet in web design .pptcascading style sheet in web design .ppt
cascading style sheet in web design .ppt
lekhacce
 
cascadingstylesheets,introduction.css styles-210909054722.pptx
cascadingstylesheets,introduction.css styles-210909054722.pptxcascadingstylesheets,introduction.css styles-210909054722.pptx
cascadingstylesheets,introduction.css styles-210909054722.pptx
hannahroseline2
 
4. Web Technology CSS Basics-1
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1
Jyoti Yadav
 
Css
CssCss
Css
Venkat Krishnan
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
smitha273566
 
Web Engineering - Introduction to CSS
Web Engineering - Introduction to CSSWeb Engineering - Introduction to CSS
Web Engineering - Introduction to CSS
Nosheen Qamar
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
smithaps4
 
Unit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology projectUnit 2 WT-CSS.pptx web technology project
Unit 2 WT-CSS.pptx web technology project
abhiramhatwar
 
Cascading Style Sheets for web browser.pptx
Cascading Style Sheets for web browser.pptxCascading Style Sheets for web browser.pptx
Cascading Style Sheets for web browser.pptx
alvindalejoyosa1
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
Singsys Pte Ltd
 
Cascading style sheets, Introduction to web programming
Cascading style sheets, Introduction to web programmingCascading style sheets, Introduction to web programming
Cascading style sheets, Introduction to web programming
LikhithaBrunda
 
Castro Chapter 7
Castro Chapter 7Castro Chapter 7
Castro Chapter 7
Jeff Byrnes
 
Web application is an application that is accessed by web visitor over intern...
Web application is an application that is accessed by web visitor over intern...Web application is an application that is accessed by web visitor over intern...
Web application is an application that is accessed by web visitor over intern...
MdAmreen
 
cascading style sheet in web design .ppt
cascading style sheet in web design .pptcascading style sheet in web design .ppt
cascading style sheet in web design .ppt
lekhacce
 
cascadingstylesheets,introduction.css styles-210909054722.pptx
cascadingstylesheets,introduction.css styles-210909054722.pptxcascadingstylesheets,introduction.css styles-210909054722.pptx
cascadingstylesheets,introduction.css styles-210909054722.pptx
hannahroseline2
 
4. Web Technology CSS Basics-1
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1
Jyoti Yadav
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
smitha273566
 
Web Engineering - Introduction to CSS
Web Engineering - Introduction to CSSWeb Engineering - Introduction to CSS
Web Engineering - Introduction to CSS
Nosheen Qamar
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
smithaps4
 
Ad

More from Steve Guinan (20)

Chapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationChapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and Animation
Steve Guinan
 
Chapter 17: Responsive Web Design
Chapter 17: Responsive Web DesignChapter 17: Responsive Web Design
Chapter 17: Responsive Web Design
Steve Guinan
 
Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning
Steve Guinan
 
Chapter 9: Forms
Chapter 9: FormsChapter 9: Forms
Chapter 9: Forms
Steve Guinan
 
Chapter 8: Tables
Chapter 8: TablesChapter 8: Tables
Chapter 8: Tables
Steve Guinan
 
Chapter 23: Web Images
Chapter 23: Web ImagesChapter 23: Web Images
Chapter 23: Web Images
Steve Guinan
 
Chapter 7: Images
Chapter 7: ImagesChapter 7: Images
Chapter 7: Images
Steve Guinan
 
HubSpot Student Instructions
HubSpot Student InstructionsHubSpot Student Instructions
HubSpot Student Instructions
Steve Guinan
 
Ch 6: Links
Ch 6: LinksCh 6: Links
Ch 6: Links
Steve Guinan
 
Ch 5: Marking up Text
Ch 5: Marking up TextCh 5: Marking up Text
Ch 5: Marking up Text
Steve Guinan
 
Ch 3: Big Concepts
Ch 3: Big ConceptsCh 3: Big Concepts
Ch 3: Big Concepts
Steve Guinan
 
Ch 2: How the Web Works
Ch 2: How the Web WorksCh 2: How the Web Works
Ch 2: How the Web Works
Steve Guinan
 
Ch 1: Getting Started
Ch 1: Getting StartedCh 1: Getting Started
Ch 1: Getting Started
Steve Guinan
 
Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7
Steve Guinan
 
Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6
Steve Guinan
 
Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5
Steve Guinan
 
Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4 Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4
Steve Guinan
 
Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3 Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3
Steve Guinan
 
Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2 Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2
Steve Guinan
 
Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1
Steve Guinan
 
Chapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationChapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and Animation
Steve Guinan
 
Chapter 17: Responsive Web Design
Chapter 17: Responsive Web DesignChapter 17: Responsive Web Design
Chapter 17: Responsive Web Design
Steve Guinan
 
Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning
Steve Guinan
 
Chapter 23: Web Images
Chapter 23: Web ImagesChapter 23: Web Images
Chapter 23: Web Images
Steve Guinan
 
HubSpot Student Instructions
HubSpot Student InstructionsHubSpot Student Instructions
HubSpot Student Instructions
Steve Guinan
 
Ch 5: Marking up Text
Ch 5: Marking up TextCh 5: Marking up Text
Ch 5: Marking up Text
Steve Guinan
 
Ch 3: Big Concepts
Ch 3: Big ConceptsCh 3: Big Concepts
Ch 3: Big Concepts
Steve Guinan
 
Ch 2: How the Web Works
Ch 2: How the Web WorksCh 2: How the Web Works
Ch 2: How the Web Works
Steve Guinan
 
Ch 1: Getting Started
Ch 1: Getting StartedCh 1: Getting Started
Ch 1: Getting Started
Steve Guinan
 
Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 7
Steve Guinan
 
Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 6
Steve Guinan
 
Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 5
Steve Guinan
 
Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4 Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 4
Steve Guinan
 
Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3 Intro to Web Design 6e Chapter 3
Intro to Web Design 6e Chapter 3
Steve Guinan
 
Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2 Intro to Web Design 6e Chapter 2
Intro to Web Design 6e Chapter 2
Steve Guinan
 
Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1Intro to Web Design 6e Chapter 1
Intro to Web Design 6e Chapter 1
Steve Guinan
 
Ad

Recently uploaded (19)

project_based_laaaaaaaaaaearning,kelompok 10.pptx
project_based_laaaaaaaaaaearning,kelompok 10.pptxproject_based_laaaaaaaaaaearning,kelompok 10.pptx
project_based_laaaaaaaaaaearning,kelompok 10.pptx
redzuriel13
 
Best web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you businessBest web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you business
steve198109
 
IT Services Workflow From Request to Resolution
IT Services Workflow From Request to ResolutionIT Services Workflow From Request to Resolution
IT Services Workflow From Request to Resolution
mzmziiskd
 
White and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptxWhite and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptx
canumatown
 
(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security
aluacharya169
 
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHostingTop Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
steve198109
 
APNIC Update, presented at NZNOG 2025 by Terry Sweetser
APNIC Update, presented at NZNOG 2025 by Terry SweetserAPNIC Update, presented at NZNOG 2025 by Terry Sweetser
APNIC Update, presented at NZNOG 2025 by Terry Sweetser
APNIC
 
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 SupportReliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
steve198109
 
DNS Resolvers and Nameservers (in New Zealand)
DNS Resolvers and Nameservers (in New Zealand)DNS Resolvers and Nameservers (in New Zealand)
DNS Resolvers and Nameservers (in New Zealand)
APNIC
 
Computers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers NetworksComputers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers Networks
Tito208863
 
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
DataProvider1
 
Understanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep WebUnderstanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep Web
nabilajabin35
 
Perguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolhaPerguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolha
socaslev
 
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation TemplateSmart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
yojeari421237
 
Determining Glass is mechanical textile
Determining  Glass is mechanical textileDetermining  Glass is mechanical textile
Determining Glass is mechanical textile
Azizul Hakim
 
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC
 
5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx
andani26
 
highend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptxhighend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptx
elhadjcheikhdiop
 
OSI TCP IP Protocol Layers description f
OSI TCP IP Protocol Layers description fOSI TCP IP Protocol Layers description f
OSI TCP IP Protocol Layers description f
cbr49917
 
project_based_laaaaaaaaaaearning,kelompok 10.pptx
project_based_laaaaaaaaaaearning,kelompok 10.pptxproject_based_laaaaaaaaaaearning,kelompok 10.pptx
project_based_laaaaaaaaaaearning,kelompok 10.pptx
redzuriel13
 
Best web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you businessBest web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you business
steve198109
 
IT Services Workflow From Request to Resolution
IT Services Workflow From Request to ResolutionIT Services Workflow From Request to Resolution
IT Services Workflow From Request to Resolution
mzmziiskd
 
White and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptxWhite and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptx
canumatown
 
(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security
aluacharya169
 
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHostingTop Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
steve198109
 
APNIC Update, presented at NZNOG 2025 by Terry Sweetser
APNIC Update, presented at NZNOG 2025 by Terry SweetserAPNIC Update, presented at NZNOG 2025 by Terry Sweetser
APNIC Update, presented at NZNOG 2025 by Terry Sweetser
APNIC
 
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 SupportReliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
steve198109
 
DNS Resolvers and Nameservers (in New Zealand)
DNS Resolvers and Nameservers (in New Zealand)DNS Resolvers and Nameservers (in New Zealand)
DNS Resolvers and Nameservers (in New Zealand)
APNIC
 
Computers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers NetworksComputers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers Networks
Tito208863
 
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
DataProvider1
 
Understanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep WebUnderstanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep Web
nabilajabin35
 
Perguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolhaPerguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolha
socaslev
 
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation TemplateSmart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
yojeari421237
 
Determining Glass is mechanical textile
Determining  Glass is mechanical textileDetermining  Glass is mechanical textile
Determining Glass is mechanical textile
Azizul Hakim
 
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC
 
5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx
andani26
 
highend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptxhighend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptx
elhadjcheikhdiop
 
OSI TCP IP Protocol Layers description f
OSI TCP IP Protocol Layers description fOSI TCP IP Protocol Layers description f
OSI TCP IP Protocol Layers description f
cbr49917
 

Chapter 11: Intro to CSS

  • 2. OVERVIEW • The benefits of CSS • Understanding document structure • Writing style rules • Attaching styles to the HTML document • Inheritance • The cascade • The box model • CSS units of measurement
  • 3. The Benefits of CSS • Precise type and layout control • Less work: Change look of the whole site with one edit • Accessibility: Markup stays semantic • Flexibility: The same HTML markup can be made to appear in dramatically different ways
  • 4. Style Separate from Structure These pages have the exact same HTML source but different style sheets: (csszengarden.com)
  • 5. How Style Sheets Work 1. Start with a marked up document (like HTML, but could be another XML markup language). 2. Write styles for how you want elements to look using CSS syntax. 3. Attach the styles to the document (there are a number of ways). 4. The browser uses your instructions when rendering the elements.
  • 6. Style Rules Each rule selects an element and declares how it should display. h1 { color: green; } This rule selects all h1 elements and declares that they should be green. strong { color: red; font-style: italic; } This rule selects all strong inline elements and declares that they should be red and in an italic font.
  • 7. Style Rule Structure • A style rule is made up of a selector a declaration. • The declaration is one or more property / value pairs.
  • 8. Selectors There are many types of selectors. Here are just two examples: p {property: value;} Element type selector: Selects all elements of this type (p) in the document. #intro {property: value} ID selector (indicated by the # symbol) selects by ID value. In the example, an element with an id of “intro” would be selected.
  • 9. Declarations The declaration is made up of a property/value pair contained in curly brackets { }: selector { property: value; } Example h2 { color: red; font-size: 2em; margin-left: 30px; opacity: .5; }
  • 10. Declarations (cont’d) • End each declaration with a semicolon to keep it separate from the next declaration. • White space is ignored, so you can stack declarations to make them easier to read. • Properties are defined in the CSS specifications. • Values are dependent on the type of property: • Measurements • Keywords • Color values • More
  • 11. CSS Comments /* comment goes here */ • Content between /* and */ will be ignored by the browser. • Useful for leaving notes or section labels in the style sheet. • Can be used within rules to temporarily hide style declarations in the design process.
  • 12. Adding Styles to the Document There are three ways to attach a style sheet to a document: External style sheets A separate, text-only .css file associated with the document with the link element or @import rule Embedded style sheets Styles are listed in the head of the HTML document in the style element. Inline styles Properties and values are added to an individual element with the style attribute.
  • 13. External Style Sheets The style rules are saved in a separate text-only .css file and attached via link or @import. Via link element in HTML: <head> <title>Titles are require</title> <link rel="stylesheet" href="/path/example.css"> </head> Via @import rule in a style sheet: <head> <title>Titles are required</title> <style> @import url("/path/example.css"); p {font-face: Verdana;} </style> </head>
  • 14. Embedded Style Sheets Embedded style sheets are placed in the head of the document via the style element: <head> <title>Titles are required</title> <style> /* style rules go here */ </style> </head>
  • 15. Inline Styles Apply a style declaration to a single element with the style attribute: <p style="font-size: large;">Paragraph text...</p> To add multiple properties, separate them with semicolons: <h3 style="color: red; margin-top: 30px;">Intro</h3>
  • 16. Document Structure Documents have an implicit structure. We give certain relationships names, as if they’re a family: • All the elements contained in a given element are its descendents. • An element that is directly contained within another element is the child of that element. • The containing element is the parent of the contained element. • Two elements with the same parent are siblings.
  • 17. Inheritance • Many properties applied to elements are passed down to the elements they contain. This is called inheritance. • For example, applying a sans-serif font to a p element causes the em element it contains to be sans-serif as well:
  • 18. Inheritance (cont’d) • Some properties inherit; others do not. Properties related to text usually inherit; properties related to layout generally don’t. • Styles explicitly applied to specific elements override inherited styles. • You’ll learn to use inheritance strategically to keep your style rules simple.
  • 19. The Cascade • The cascade refers to the system for resolving conflicts when several styles apply to the same element. • Style information is passed down (it “cascades” down) until overwritten by a style rule with more weight. • Weight is considered based on: • Priority of style rule source • Specificity of the selector • Rule order
  • 20. The Cascade: Priority Style rules from sources higher in this list override rules from sources listed below them. • Any style marked as !important by the user (to accommodate potential accessibility settings) • Any style marked !important by the author (of the web page) • Author styles (style sheets created in web site production) • User styles (added by the reader) • User agent styles (browser defaults)
  • 21. The Cascade: Specificity • When two rules in a single style sheet conflict, the type of selector is used to determine which rule has more weight. • For example, ID selectors are more specific than general element selectors. NOTE: Specificity will be discussed once we have covered more selector types.
  • 22. The Cascade: Rule Order • When two rules have equal weight, rule order is used. Whichever rule appears last “wins.” <style> p {color: red;} p {color: blue;} p {color: green;} </style> In this example, paragraphs would be green. • Styles may come in from external style sheets, embedded style rules, and inline styles. The style rule that gets parsed last (the one closest to the content) will apply.
  • 23. The Box Model Browsers see every element on the page as being contained in a little rectangular box. Block elements and inline elements participate in the box model. In this example, a blue border is added to all elements.
  • 24. The Box Model (cont’d) • The box model is the foundation of CSS page layout. • Apply properties such as borders, margins, padding, and backgrounds to element boxes. • Position, move, grow, and shrink boxes to create fixed or flexible page layouts.
  • 25. CSS Units of Measurement CSS provides a variety ways to specify measurements: Absolute units Have predefined meanings or real-world equivalents Relative units Based on the size of something else, such as the default text size or the size of the parent element Percentages Calculated relative to another value, such as the size of the parent element
  • 26. Absolute Units With the exception of pixels, absolute units are not appropriate for web design: px pixel in inches mm millimeters cm centimeters q 1/4 millimeter pt points (1/72 inch) pc pica (1 pica = 12 points = 1/6 inch)
  • 27. Relative Units Relative units are based on the size of something else: em a unit equal to the current font size ex x-height, equal to the height of a lowercase x rem root em, equal to the font size of the html element ch zero width, equal to the width of a zero (0) vw viewport width unit (equal to 1/100 of viewport width) vh viewport height unit (1/100 of viewport height) vmin viewport minimum unit (value of vh or vw, whichever is smaller) vmax viewport maximum unit (value of vh or vw, whichever is larger)
  • 28. RELATIVE UNITS The rem Unit • The rem (root em) unit is based on the font size of the html element, whatever that happens to be. • Default in modern browsers: Root font size is 16 pixels, so a rem = a 16-pixel unit. • If the root font size of the document changes, so does the size of a rem (and that’s good for keeping elements proportional).
  • 29. RELATIVE UNITS The em Unit • The em unit is traditionally based on the width of a capital letter M in the font. • When the font size is 16 pixels,1em = 16 pixels, 2em = 32 pixels, and so on. NOTE: Because they’re based on the font size of the current element, the size of an em may not be consistent across a page.
  • 30. RELATIVE UNITS Viewport Percentage Lengths (vw/vh) Viewport width (vw) and viewport height (vh) units are relative to the size of the viewport (browser window): vh = 1/100th width of viewport vh = 1/100th height of viewport They’re useful for making an element fill the viewport or a specified percentage of it. This image will be 50% the width and height of the viewport: img { width: 50vw; height: 50vh; }
  • 31. Browser Developer Tools Major browsers have built-in tools that aid development: • HTML, CSS, and JavaScript inspectors • Network speed reports • Animation tools • Other helpful features
  • 32. Browser Developer Tools (cont’d) Chrome DevTools (View > Developer > Developer Tools) Firefox, Safari, Opera, and Microsoft Edge also have developer tools.