SlideShare a Scribd company logo
1 of 22
Unit 1: Web Fundamentals
Lesson 10: 3 Ways to Use CSS
August 24, 2013
Lesson 10: 3 Ways to Use CSS
2
Introduction
to HTML
Learning to
Use HTML
HTML and
Email
History and
Future of the
Web
HTML and
Forms
Search
Engine
Optimization
Learning to
Use CSS
Introduction
to CSS
Reusing
Code
3 Ways to
Use CSS
Separation of
Concerns
Launching
Your Own
Website
Lesson 1 Lesson 2 Lesson 3 Lesson 4
Lesson 8 Lesson 7 Lesson 6 Lesson 5
Lesson 9 Lesson 10 Lesson 11 Lesson 12
Build understanding Develop skills
Recap from last time (I)
• It’s important to divide our HTML pages from our CSS files
1. It saves us time by reusing code. We can link multiple HTML
pages with a single CSS stylesheet.
3
www.codecademy.com www.codecademy.com/about
Both pages share the same navigation bar,
and probably the same CSS stylesheet!
Recap from last time (II)
2. It helps us debug our code. By keeping the files separate, it
makes our code easier to read, which helps us find our mistakes.
4
<html>
<head>
</head>
<body>
<p>Avoid code bloat!</p>
</body>
</html>
body {
text-align: center;
p {color: red;}
}
<html>
<head>
<style type=“text/css”>
body {text-align: center;}
</style>
</head>
<body>
<p style=“color: red;”>
Avoid code bloat!
</p>
</body>
</html>
HTML mixed with CSS HTML only
CSS only
This is code bloat!
Recap from last time (III)
3. It keeps us organized. Separation of concerns splits our code into
sections, which helps us to work together in teams.
5
Header
Footer
Signup form
Login form
There are actually multiple ways to use CSS
• Last time, we saw why it’s best to keep our CSS files in a separate
stylesheet from our HTML files
• This way is still the best, but it is not the only way – there are
actually three ways to use CSS
• It’s important to understand all the possible ways because while we
will keep our CSS files separate, others may not always do so
6
Three possible ways to work with CSS
1. Keep CSS in a separate stylesheet
2. Add inline CSS to HTML tags
1. Embed CSS in the HTML
7
Keeping CSS separate is still the best
• As we saw earlier, having a separate CSS stylesheet helps us
reuse code, debug mistakes, and stay organized
• This is true even when we use other people’s code
• For example, if we find a CSS stylesheet online that we like, we
can download it and import it into our own CSS file
8
my-file.css
body {
background-color: blue;
font-family: copperplate;
}
new-styles.css
@import “new-styles.css”
body {
text-align: center;
p {color: red;}
}
Three possible ways to work with CSS
1. Keep CSS in a separate stylesheet
2. Add inline CSS to HTML tags
1. Embed CSS in the HTML
9
We can also add inline CSS to HTML tags
• The second possible way to work with CSS is to add it inline (within
the same line) as our HTML
• As you can see below, the CSS styles for the <p> tag appears
inline with the <p> tag itself
10
<html>
<head>
</head>
<body>
<p style=“color: red;”>
Avoid code bloat!
</p>
</body>
</html>
HTML file
Inline CSS
Why do people sometimes use this?
• People will sometimes use inline CSS because it’s a way to quickly
add styling to a tag without having to switch to a different file
11
<html>
<head>
</head>
<body>
<p style=“color: red;”>
Avoid code bloat!
</p>
</body>
</html>
HTML with inline CSS
<html>
<head>
</head>
<body>
<p>
Avoid code bloat!
</p>
</body>
</html>
HTML file
p {color: red;}
CSS file
vs.
Best to keep a separate stylesheet
• Harder to reuse code using the inline CSS method because we
need to add the CSS within every HTML tag
• Inline CSS will also often lead to code bloat
• May save a little time upfront, but can lead to A LOT of time
wasted when debugging!
12
Don’t let yourself fall into the trap!
Three possible ways to work with CSS
1. Keep CSS in a separate stylesheet
2. Add inline CSS to HTML tags
1. Embed CSS in the HTML
13
Why do people sometimes use this?
• People will sometimes use embedded CSS if they only have one
webpage and will not need to reuse code on multiple pages
14
<html>
<head>
<style type=“text/css”>
p {color: red;}
</style>
</head>
<body>
<p>
Avoid code bloat!
</p>
</body>
</html>
HTML with embedded CSS
<html>
<head>
</head>
<body>
<p>
Avoid code bloat!
</p>
</body>
</html>
HTML file
p {color: red;}
CSS file
vs.
Embedded CSS always appears between the <head> tags
Still best to keep a separate stylesheet
• Embedded CSS prevents us from reusing code across multiple
pages, and nearly all websites have multiple pages!
• An exception is when you are building a landing page (a one-page
website usually designed to advertise a business)
15
Landing page for a hotel Landing page for
learning French
What happens when different methods conflict?
• You may occasionally see code where multiple methods are being
used (for example, CSS could be inline AND embedded)
• If there is ever a conflict:
16
Inline CSS has
highest priority
Embedded CSS has
second priority
Separate stylesheets
have lowest priority
Exercise 1: Can you identify the different types
of CSS below? (I)
17
my-file.html
p {color: black;}
styles.css
<html>
<head>
<link rel=“stylesheet”
type=“text/css”
href=“styles.css”>
<style type=“text/css”>
p {color: blue;}
</style>
</head>
<body>
<p style=“color: red;”>
What color am I?
</p>
</body>
</html>
Exercise 1: Can you identify the different types
of CSS below? (II)
18
my-file.html
p {color: black;}
styles.css
Embedded CSS
appears in the
<head> of the file
Inline CSS appears
in the HTML tag
Separate stylesheets appear
in…separate CSS stylesheets
<html>
<head>
<link rel=“stylesheet”
type=“text/css”
href=“styles.css”>
<style type=“text/css”>
p {color: blue;}
</style>
</head>
<body>
<p style=“color: red;”>
What color am I?
</p>
</body>
</html>
Exercise 2: What font color will we see when we
open these files in our browser? (I)
19
my-file.html
p {color: black;}
styles.css
Embedded CSS
appears in the
<head> of the file
Inline CSS appears
in the HTML tag
Separate stylesheets appear
in…separate CSS stylesheets
<html>
<head>
<style type=“text/css”>
p {color: blue;}
</style>
</head>
<body>
<p style=“color: red;”>
What color am I?
</p>
</body>
</html>
Exercise 2: What font color will we see when we
open these files in our browser? (II)
20
• The text will appear red.
• Remember, inline CSS has highest priority, embedded CSS is
second, and separate stylesheets come last
Summary
• There are three ways to work with CSS:
– In a separate stylesheet (we want to do this)
– Inline with HTML tags
– Embedded in the <head> of the HTML file
• When conflicts occur,
21
Inline CSS has
highest priority
Embedded CSS has
second priority
Separate stylesheets
have lowest priority
What to do on your own
1. Go to URL to complete the Codecademy course online
2. Do the practice set on the material learned
1. Take the follow-up quiz to test your understanding
22

More Related Content

What's hot

What's hot (20)

Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Introduction to the Web and HTML
Introduction to the Web and HTMLIntroduction to the Web and HTML
Introduction to the Web and HTML
 
Lecture2 CSS1
Lecture2  CSS1Lecture2  CSS1
Lecture2 CSS1
 
1. html introduction
1. html introduction1. html introduction
1. html introduction
 
Lesson 2: Getting To Know HTML
Lesson 2: Getting To Know HTMLLesson 2: Getting To Know HTML
Lesson 2: Getting To Know HTML
 
Html
HtmlHtml
Html
 
Web development basics
Web development basicsWeb development basics
Web development basics
 
Introducing HTML
Introducing HTMLIntroducing HTML
Introducing HTML
 
HTML standards
HTML standardsHTML standards
HTML standards
 
Html
HtmlHtml
Html
 
Solving Common Client Requets with jQuery Presentation (v2)
Solving Common Client Requets with jQuery Presentation (v2)Solving Common Client Requets with jQuery Presentation (v2)
Solving Common Client Requets with jQuery Presentation (v2)
 
The Dark Arts of CSS
The Dark Arts of CSSThe Dark Arts of CSS
The Dark Arts of CSS
 
Html for beginners
Html for beginnersHtml for beginners
Html for beginners
 
A blog can be a fantastic teaching tool
A blog can be a fantastic teaching tool A blog can be a fantastic teaching tool
A blog can be a fantastic teaching tool
 
Graphics For Web
Graphics For WebGraphics For Web
Graphics For Web
 
Html.ppt
Html.pptHtml.ppt
Html.ppt
 
Front-end development introduction (JavaScript). Part 2
Front-end development introduction (JavaScript). Part 2Front-end development introduction (JavaScript). Part 2
Front-end development introduction (JavaScript). Part 2
 
Shareist
ShareistShareist
Shareist
 
Block google from indexing your word press site
Block google  from indexing your word press siteBlock google  from indexing your word press site
Block google from indexing your word press site
 
WordPress
WordPressWordPress
WordPress
 

Viewers also liked

Lesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ayLesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ayCodecademy Ren
 
Lesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ayLesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ayCodecademy Ren
 
Lesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayLesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayCodecademy Ren
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayCodecademy Ren
 
Lesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayLesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayCodecademy Ren
 
Lesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ayLesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ayCodecademy Ren
 
Lesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayCodecademy Ren
 
Lesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayLesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayCodecademy Ren
 
Lesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayLesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayCodecademy Ren
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayCodecademy Ren
 

Viewers also liked (10)

Lesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ayLesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ay
 
Lesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ayLesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ay
 
Lesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayLesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ay
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ay
 
Lesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayLesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ay
 
Lesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ayLesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ay
 
Lesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ay
 
Lesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayLesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ay
 
Lesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayLesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ay
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ay
 

Similar to Lesson 110 24 aug13-1400-ay

Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSSanjoy Kr. Paul
 
Shyam sunder Rajasthan Computer
Shyam sunder Rajasthan ComputerShyam sunder Rajasthan Computer
Shyam sunder Rajasthan Computershyamverma305
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.docbutest
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.docbutest
 
The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbookjackchenvlo
 
HTML/CSS Workshop @ Searchcamp
HTML/CSS Workshop @ SearchcampHTML/CSS Workshop @ Searchcamp
HTML/CSS Workshop @ SearchcampJames Mills
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8RohanMistry15
 
Unit iii css and javascript 1
Unit iii css and javascript 1Unit iii css and javascript 1
Unit iii css and javascript 1Jesus Obenita Jr.
 
Css week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandourCss week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Gheyath M. Othman
 

Similar to Lesson 110 24 aug13-1400-ay (20)

Css Basics
Css BasicsCss Basics
Css Basics
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
Shyam sunder Rajasthan Computer
Shyam sunder Rajasthan ComputerShyam sunder Rajasthan Computer
Shyam sunder Rajasthan Computer
 
Full
FullFull
Full
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
 
Lecture-6.pptx
Lecture-6.pptxLecture-6.pptx
Lecture-6.pptx
 
CSS.ppt
CSS.pptCSS.ppt
CSS.ppt
 
Css
CssCss
Css
 
HTML/CSS Workshop @ Searchcamp
HTML/CSS Workshop @ SearchcampHTML/CSS Workshop @ Searchcamp
HTML/CSS Workshop @ Searchcamp
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8
 
Unit iii css and javascript 1
Unit iii css and javascript 1Unit iii css and javascript 1
Unit iii css and javascript 1
 
Css week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandourCss week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandour
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
css1.pptx
css1.pptxcss1.pptx
css1.pptx
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 

More from Codecademy Ren

Lesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayLesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayCodecademy Ren
 
Lesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayLesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayCodecademy Ren
 
Lesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayLesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayCodecademy Ren
 
Lesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayLesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayCodecademy Ren
 
Lesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayLesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayCodecademy Ren
 
Lesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayLesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayCodecademy Ren
 
Lesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayLesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayCodecademy Ren
 
Lesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayLesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayCodecademy Ren
 

More from Codecademy Ren (8)

Lesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayLesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ay
 
Lesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayLesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ay
 
Lesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayLesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ay
 
Lesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayLesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ay
 
Lesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayLesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ay
 
Lesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayLesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ay
 
Lesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayLesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ay
 
Lesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayLesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ay
 

Recently uploaded

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Lesson 110 24 aug13-1400-ay

  • 1. Unit 1: Web Fundamentals Lesson 10: 3 Ways to Use CSS August 24, 2013
  • 2. Lesson 10: 3 Ways to Use CSS 2 Introduction to HTML Learning to Use HTML HTML and Email History and Future of the Web HTML and Forms Search Engine Optimization Learning to Use CSS Introduction to CSS Reusing Code 3 Ways to Use CSS Separation of Concerns Launching Your Own Website Lesson 1 Lesson 2 Lesson 3 Lesson 4 Lesson 8 Lesson 7 Lesson 6 Lesson 5 Lesson 9 Lesson 10 Lesson 11 Lesson 12 Build understanding Develop skills
  • 3. Recap from last time (I) • It’s important to divide our HTML pages from our CSS files 1. It saves us time by reusing code. We can link multiple HTML pages with a single CSS stylesheet. 3 www.codecademy.com www.codecademy.com/about Both pages share the same navigation bar, and probably the same CSS stylesheet!
  • 4. Recap from last time (II) 2. It helps us debug our code. By keeping the files separate, it makes our code easier to read, which helps us find our mistakes. 4 <html> <head> </head> <body> <p>Avoid code bloat!</p> </body> </html> body { text-align: center; p {color: red;} } <html> <head> <style type=“text/css”> body {text-align: center;} </style> </head> <body> <p style=“color: red;”> Avoid code bloat! </p> </body> </html> HTML mixed with CSS HTML only CSS only This is code bloat!
  • 5. Recap from last time (III) 3. It keeps us organized. Separation of concerns splits our code into sections, which helps us to work together in teams. 5 Header Footer Signup form Login form
  • 6. There are actually multiple ways to use CSS • Last time, we saw why it’s best to keep our CSS files in a separate stylesheet from our HTML files • This way is still the best, but it is not the only way – there are actually three ways to use CSS • It’s important to understand all the possible ways because while we will keep our CSS files separate, others may not always do so 6
  • 7. Three possible ways to work with CSS 1. Keep CSS in a separate stylesheet 2. Add inline CSS to HTML tags 1. Embed CSS in the HTML 7
  • 8. Keeping CSS separate is still the best • As we saw earlier, having a separate CSS stylesheet helps us reuse code, debug mistakes, and stay organized • This is true even when we use other people’s code • For example, if we find a CSS stylesheet online that we like, we can download it and import it into our own CSS file 8 my-file.css body { background-color: blue; font-family: copperplate; } new-styles.css @import “new-styles.css” body { text-align: center; p {color: red;} }
  • 9. Three possible ways to work with CSS 1. Keep CSS in a separate stylesheet 2. Add inline CSS to HTML tags 1. Embed CSS in the HTML 9
  • 10. We can also add inline CSS to HTML tags • The second possible way to work with CSS is to add it inline (within the same line) as our HTML • As you can see below, the CSS styles for the <p> tag appears inline with the <p> tag itself 10 <html> <head> </head> <body> <p style=“color: red;”> Avoid code bloat! </p> </body> </html> HTML file Inline CSS
  • 11. Why do people sometimes use this? • People will sometimes use inline CSS because it’s a way to quickly add styling to a tag without having to switch to a different file 11 <html> <head> </head> <body> <p style=“color: red;”> Avoid code bloat! </p> </body> </html> HTML with inline CSS <html> <head> </head> <body> <p> Avoid code bloat! </p> </body> </html> HTML file p {color: red;} CSS file vs.
  • 12. Best to keep a separate stylesheet • Harder to reuse code using the inline CSS method because we need to add the CSS within every HTML tag • Inline CSS will also often lead to code bloat • May save a little time upfront, but can lead to A LOT of time wasted when debugging! 12 Don’t let yourself fall into the trap!
  • 13. Three possible ways to work with CSS 1. Keep CSS in a separate stylesheet 2. Add inline CSS to HTML tags 1. Embed CSS in the HTML 13
  • 14. Why do people sometimes use this? • People will sometimes use embedded CSS if they only have one webpage and will not need to reuse code on multiple pages 14 <html> <head> <style type=“text/css”> p {color: red;} </style> </head> <body> <p> Avoid code bloat! </p> </body> </html> HTML with embedded CSS <html> <head> </head> <body> <p> Avoid code bloat! </p> </body> </html> HTML file p {color: red;} CSS file vs. Embedded CSS always appears between the <head> tags
  • 15. Still best to keep a separate stylesheet • Embedded CSS prevents us from reusing code across multiple pages, and nearly all websites have multiple pages! • An exception is when you are building a landing page (a one-page website usually designed to advertise a business) 15 Landing page for a hotel Landing page for learning French
  • 16. What happens when different methods conflict? • You may occasionally see code where multiple methods are being used (for example, CSS could be inline AND embedded) • If there is ever a conflict: 16 Inline CSS has highest priority Embedded CSS has second priority Separate stylesheets have lowest priority
  • 17. Exercise 1: Can you identify the different types of CSS below? (I) 17 my-file.html p {color: black;} styles.css <html> <head> <link rel=“stylesheet” type=“text/css” href=“styles.css”> <style type=“text/css”> p {color: blue;} </style> </head> <body> <p style=“color: red;”> What color am I? </p> </body> </html>
  • 18. Exercise 1: Can you identify the different types of CSS below? (II) 18 my-file.html p {color: black;} styles.css Embedded CSS appears in the <head> of the file Inline CSS appears in the HTML tag Separate stylesheets appear in…separate CSS stylesheets <html> <head> <link rel=“stylesheet” type=“text/css” href=“styles.css”> <style type=“text/css”> p {color: blue;} </style> </head> <body> <p style=“color: red;”> What color am I? </p> </body> </html>
  • 19. Exercise 2: What font color will we see when we open these files in our browser? (I) 19 my-file.html p {color: black;} styles.css Embedded CSS appears in the <head> of the file Inline CSS appears in the HTML tag Separate stylesheets appear in…separate CSS stylesheets <html> <head> <style type=“text/css”> p {color: blue;} </style> </head> <body> <p style=“color: red;”> What color am I? </p> </body> </html>
  • 20. Exercise 2: What font color will we see when we open these files in our browser? (II) 20 • The text will appear red. • Remember, inline CSS has highest priority, embedded CSS is second, and separate stylesheets come last
  • 21. Summary • There are three ways to work with CSS: – In a separate stylesheet (we want to do this) – Inline with HTML tags – Embedded in the <head> of the HTML file • When conflicts occur, 21 Inline CSS has highest priority Embedded CSS has second priority Separate stylesheets have lowest priority
  • 22. What to do on your own 1. Go to URL to complete the Codecademy course online 2. Do the practice set on the material learned 1. Take the follow-up quiz to test your understanding 22