SlideShare une entreprise Scribd logo
1  sur  33
Introduction
To CSS
by: Faizan Ahmed
HTML Review
► What is HTML used for?
► Give some examples of formatting tags in HTML?
► HTML is the most widely used language on the
Web
► In today’s lesson we will be discussing the
second most widely used language on the web
► Does anyone know the name of the second most
widely used language?
Lesson 1: History of CSS
► CSS was proposed in 1994 as a web styling
language. To helps solve some of the
problems HTML 4.
► CSS2 became the recommendation in 1998
by W3C
► CSS3 was started in 1998 but it has never
been completed. Some parts are still being
developed and some components work on
some browsers.
Lesson 1: What is CSS?
• CSS stands for Cascading Style Sheets
• Styles - define how to display HTML elements
• Styles are normally stored in Style Sheets
Definition:
Cascading Style Sheets (CSS) – is a rule based language
that applies styling to your HTML elements. You write
CSS rules in elements, and modify properties of those
elements such as color, background color, width, border
thickness, font size, etc.
Lesson 2: Syntax of CSS
 The CSS syntax is made up of 5 parts:
 selector
 property/value
 declaration
 declaration block
 curly braces
We will explore each part in the next slides.
Selector
 Definition: identifies the HTML elements that
the rule will be applied to, identified by the
actual element name, e.g. <body>, or by other
means such as class attribute values.
 Example:
*The selector is normally the HTML element you want to style
Declaration Block
Definition: multiple declaration lines including the
curly braces
Declaration
 Definition: Each CSS line that includes property
and value
*Each declaration consists of a property and a value.
Property & Value
 Definition: The property is the style attribute
you want to change. Each property has a value.
*Properties are separated from their respective values by colons :
*Pairs are separated from each other by semicolons ;
Curly Braces
 Definition: the curly braces contain the
properties of the element you want to
manipulate, and the values that you want to
change them to. The curly braces plus their
content is called a declaration block.
 Example:
Lesson 2 Assignment:
Let’s Create Our First CSS Page
► Open Notepad
► Type the following Code
<html>
<head>
<style type="text/css">
p {color:red; text-align:center;}
</style>
</head>
<body>
<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
</body>
</html>
► Save Your File as css-myfirstpage.html into a new folder called CSS
Lesson 3: Class and id Selectors
 In addition to setting a style for a HTML element, CSS allows
you to specify your own selectors called "id" and "class".
id - The id selector is used to specify a style for a single, unique
element.
 The id selector uses the id attribute of the HTML element,
and is defined with a "#".
 The style rule below will be applied to the element with
id="para1":
 #para1 {text-align:center;color:red;}
Lesson 3: Class and id Selectors
Class - The class selector is used to specify a style for a group of
elements. Unlike the id selector, the class selector is most
often used on several elements.
 This allows you to set a particular style for any HTML
elements with the same class.
 The class selector uses the HTML class attribute, and is
defined with a "."
 In the example below, all HTML elements with class="center"
will be center-aligned:
 .center {text-align:center;}
Lesson 3: Class and id Selectors
 In the image below what is the h1 selector an
ID or a Class?
#
.
Lesson 3 Assignment:
Let’s Create A CSS Page that uses “id”
► Open Notepad
► Type the following Code
<html>
<head>
<style type="text/css">
#para1
{
text-align:center;
color:red;
}
</style>
</head>
<body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>
► Save Your File as css-id.html into a your folder called CSS.
Lesson 3 Assignment:
Let’s Create A CSS Page that uses “class”
► Open Notepad
► Type the following Code
<html>
<head>
<style type="text/css">
.center
{
text-align:center;
}
</style>
</head>
<body>
<h1 class="center">Center-aligned heading</h1>
<p class="center">Center-aligned paragraph.</p>
</body>
</html>
► Save Your File as css-class.html into a your folder called CSS.
Lesson 3 Comments
► Comments are used to explain your code, and may help you when you edit
the source code at a later date. Comments are ignored by browsers.
► You add comments by enclosing them in
/* and */
► Comments can span several lines, and the browser will ignore these lines.
► Example:
► /* This is a basic comment it will not appear on the page*/
/* starts the comment
*/ is the end of the comment
/*This is a comment*/
p{ text-align:center; color:black; font-family:arial;}
Lesson 3 Assignment:
Let’s Add A Comment
► Open Your CSS-ID example in Notepad
► Type the following Code right above the style you had written previously.
<html>
<head>
/*This is an example of how to use ID in a CSS web page*/
<style type="text/css">
#para1
{
text-align:center;
color:red;
}
</style>
</head>
<body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>
► Save Your File as css-comment.html into a your folder called CSS.
Lesson 4: How CSS is Applied to A Web Page
►CSS is applied to a web page using three
different methods:
 Inline style
 Internal style sheet
 External style sheet
►Inline CSS
►Applies styles directly to the elements by
adding declarations into the style
►For Example:
<p style=“color: red;”> This is a simple
paragraph and the inline style makes it
red.</p>
Lesson 4: How CSS is Applied to A Web Page
► Internal Style Sheet
► Applies styles to HTML by placing the CSS rules inside the tag
<style> inside the document tag <head>.
► For Example:
<head>
<title>my page</title>
<style type=“text/css”>
p{color:red}</style>
</head>
<body>
<p>this is a simple paragraph
</p>
</body>
Lesson 4: How CSS is Applied to A Web Page
► External CSS
► Applies styles as a separate file with a .css extension. The file is
then referenced from inside the <head> element by a link to the
file.
► For Example:
<head>
<title>my external style sheet page</title>
<link rel=“style sheet” type=“text/css” href=“my-external-
stylesheet.css”>
<body>
<p>this is a simple paragraph</p>
</body>
► You can create an external style sheet in your text editor.
Lesson 4: How CSS is Applied to A Web Page
► What style sheet is best?
► Web developers rarely use inline CSS. Since they prefer
to not mix content with presentation. And it is not
efficient since you have to declare the style individually
for every component.
► Internal and External style sheets are more popular
because you can style multiple elements with one rule.
► External style sheets are best because they allow you to
save all the style information on a separate file from the
content. You can then modify a style for a site and it will
update all of the pages in a site.
Lesson 4: How CSS is Applied to A Web Page
►CSS Colors
►In the previous lesson you have seen a few
CSS styles that included color like: <p
style=“color: red;”>
►There are a few ways that you can set
colors in CSS:
Keywords, Hex values, RGB, HSL(a)
Lesson 5: Colors and Formatting in CSS
► CSS Colors: Keywords
► Using the keywords like: red, fuchsia, yellow,
blue, green you can specify what color you would
like the CSS rule to display.
► For example:
► p{color:red}
► h2{color:yellow}
► There are 17 of these keyword colors you can
use in CSS.
Lesson 5: Colors and Formatting in CSS
Keyword Color Hex
aqua #00ffff
black #000000
blue #0000ff
fuchsia #ff00ff
gray #808080
green #008000
lime #00ff00
maroon #800000
navy #000080
olive #808000
orange (added in CSS 2.1) #ffa500
purple #800080
red #ff0000
silver #c0c0c0
teal #008080
white #ffffff
yellow #ffff00
Lesson 5: Colors and Formatting in CSS
► Computers are capable of displaying a lot more
than 17 colors.
► In fact they can display approximately 16.7
million colors!
► Hex Values (hex is short for hexadecimal) are the
most common way of specifying colors for web
pages. (see hex# in the previous chart)
► For example:
p{color: #000000;}
/*This is equivalent to the keyword black*/
Lesson 5: Colors and Formatting in CSS
►Hex numbers - has 16 possible values
►0 to 9 then A to F. Which gives you 16
values.
►RGB (Red Green Blue) has the possibility of
256 colors for each (16x16)
►(R)256 x (G)256 x (B)256 = 16,777,216 or
16.7 million color values
►CSS example: h1{color: #000000;}
Lesson 5: Colors and Formatting in CSS
► RGB (a) can also help specify colors in CSS RGB
stands for Red Green Blue
► You can specify RGB in either whole numbers or
percentages
► CSS example: h1{color: rgb(0,0,0) }
/*this color is equivalent to #000000 or black */
► You use numbers from 0 to 255 which covers the
256 color range.
► More examples can be found at:
http://www.w3schools.com/css/css_colors.asp
Lesson 5: Colors and Formatting in CSS
► RGB (a) can also help specify colors in CSS RGB stands
for Red Green Blue. The “a” stands for alpha but we will
learn about that in another lesson.
► You can specify RGB in either whole numbers or
percentages
► CSS example: h1{color: rgb(0,0,0) }
/*this color is equivalent to #000000 or black */
► You use numbers from 0 to 255 which covers the 256
color range.
► More examples can be found at:
http://www.w3schools.com/css/css_colors.asp
Lesson 5: Colors and Formatting in CSS
► HSL (a) - Hue Saturation Lightness
► Similar to RGB but based on saturation and
lightness of a color
► The “a” stands for alpha but we will learn about
that in another lesson.
► CSS example: h1{color: hsl(0,100%,40%) }
► HSL accepts a number between 0 to 360 in value
► HSL also accepts percentage between 0-100%
Lesson 5: Colors and Formatting in CSS
Lesson 5 Assignment:
CSS Using Color
► Open Your CSS-ID example in Notepad
► Type the following Code right above the style you had written previously.
<html>
<body>
<p style="background-color:#FFF111">
Color set by using hex value
</p>
<p style="background-color:rgb(0,255,0);">
Color set by using rgb value
</p>
<p style="background-color:red">
Color set by using color name
</p>
</body>
</html>
► Save Your File as css-color.html into your folder called CSS
The End
►Essential Questions Review
by: Faizan Ahmed
mailtofaizanahmed@gmail.com
Facebook.com/pakifa

Contenu connexe

Tendances

Tendances (20)

Css Ppt
Css PptCss Ppt
Css Ppt
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
 
Css
CssCss
Css
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
HTML CSS Basics
HTML CSS BasicsHTML CSS Basics
HTML CSS Basics
 
Basic html tags
Basic html tagsBasic html tags
Basic html tags
 
Css Text Formatting
Css Text FormattingCss Text Formatting
Css Text Formatting
 
CSS Lists and Tables
CSS Lists and TablesCSS Lists and Tables
CSS Lists and Tables
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
Html and css
Html and cssHtml and css
Html and css
 
CSS
CSS CSS
CSS
 
Css Basics
Css BasicsCss Basics
Css Basics
 
Html introduction
Html introductionHtml introduction
Html introduction
 
Css
CssCss
Css
 

En vedette

3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
Bulldogs83
 
Css = cascading style sheets
Css = cascading style sheetsCss = cascading style sheets
Css = cascading style sheets
marteisabella
 

En vedette (20)

Flyover Margate Qld
Flyover Margate QldFlyover Margate Qld
Flyover Margate Qld
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
 
Css = cascading style sheets
Css = cascading style sheetsCss = cascading style sheets
Css = cascading style sheets
 
Introduction css
Introduction cssIntroduction css
Introduction css
 
Css
CssCss
Css
 
Php
PhpPhp
Php
 
CSS: An Introduction
CSS: An IntroductionCSS: An Introduction
CSS: An Introduction
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Floating
FloatingFloating
Floating
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Css positioning
Css positioningCss positioning
Css positioning
 
1 css introduction
1 css introduction1 css introduction
1 css introduction
 
Css
CssCss
Css
 
Css floats
Css floatsCss floats
Css floats
 
CSS Layouting #4 : Float
CSS Layouting #4 : FloatCSS Layouting #4 : Float
CSS Layouting #4 : Float
 
computerized accounting
computerized accountingcomputerized accounting
computerized accounting
 

Similaire à Introduction to css

Lecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptxLecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptx
GmachImen
 
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layout
CK Yang
 
Css introduction
Css introductionCss introduction
Css introduction
Sridhar P
 

Similaire à Introduction to css (20)

Shyam sunder Rajasthan Computer
Shyam sunder Rajasthan ComputerShyam sunder Rajasthan Computer
Shyam sunder Rajasthan Computer
 
Css Founder.com | Cssfounder org
Css Founder.com | Cssfounder orgCss Founder.com | Cssfounder org
Css Founder.com | Cssfounder org
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
 
Css
CssCss
Css
 
Lecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptxLecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptx
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Unit 2.1
Unit 2.1Unit 2.1
Unit 2.1
 
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layout
 
Unit 2.1
Unit 2.1Unit 2.1
Unit 2.1
 
Css introduction
Css introductionCss introduction
Css introduction
 
Lecture2
Lecture2Lecture2
Lecture2
 
Css notes
Css notesCss notes
Css notes
 
Lecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType ClassificationLecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType Classification
 
Cashcading stylesheets
Cashcading stylesheetsCashcading stylesheets
Cashcading stylesheets
 
Lecture-6.pptx
Lecture-6.pptxLecture-6.pptx
Lecture-6.pptx
 
CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)CSS_Day_ONE (W3schools)
CSS_Day_ONE (W3schools)
 
cascading style sheet(css).pptx
cascading style sheet(css).pptxcascading style sheet(css).pptx
cascading style sheet(css).pptx
 

Plus de Evolution Network (8)

OOP
OOPOOP
OOP
 
Funda of accounting
Funda of accountingFunda of accounting
Funda of accounting
 
Css3
Css3Css3
Css3
 
Peachtree installation guide
Peachtree installation guidePeachtree installation guide
Peachtree installation guide
 
Company formation
Company formationCompany formation
Company formation
 
How creat customers in peachtree
How creat customers in peachtreeHow creat customers in peachtree
How creat customers in peachtree
 
Cs101 a3
Cs101 a3Cs101 a3
Cs101 a3
 
Vendor in peachtree
Vendor in peachtreeVendor in peachtree
Vendor in peachtree
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Introduction to css

  • 2. HTML Review ► What is HTML used for? ► Give some examples of formatting tags in HTML? ► HTML is the most widely used language on the Web ► In today’s lesson we will be discussing the second most widely used language on the web ► Does anyone know the name of the second most widely used language?
  • 3. Lesson 1: History of CSS ► CSS was proposed in 1994 as a web styling language. To helps solve some of the problems HTML 4. ► CSS2 became the recommendation in 1998 by W3C ► CSS3 was started in 1998 but it has never been completed. Some parts are still being developed and some components work on some browsers.
  • 4. Lesson 1: What is CSS? • CSS stands for Cascading Style Sheets • Styles - define how to display HTML elements • Styles are normally stored in Style Sheets Definition: Cascading Style Sheets (CSS) – is a rule based language that applies styling to your HTML elements. You write CSS rules in elements, and modify properties of those elements such as color, background color, width, border thickness, font size, etc.
  • 5. Lesson 2: Syntax of CSS  The CSS syntax is made up of 5 parts:  selector  property/value  declaration  declaration block  curly braces We will explore each part in the next slides.
  • 6. Selector  Definition: identifies the HTML elements that the rule will be applied to, identified by the actual element name, e.g. <body>, or by other means such as class attribute values.  Example: *The selector is normally the HTML element you want to style
  • 7. Declaration Block Definition: multiple declaration lines including the curly braces
  • 8. Declaration  Definition: Each CSS line that includes property and value *Each declaration consists of a property and a value.
  • 9. Property & Value  Definition: The property is the style attribute you want to change. Each property has a value. *Properties are separated from their respective values by colons : *Pairs are separated from each other by semicolons ;
  • 10. Curly Braces  Definition: the curly braces contain the properties of the element you want to manipulate, and the values that you want to change them to. The curly braces plus their content is called a declaration block.  Example:
  • 11. Lesson 2 Assignment: Let’s Create Our First CSS Page ► Open Notepad ► Type the following Code <html> <head> <style type="text/css"> p {color:red; text-align:center;} </style> </head> <body> <p>Hello World!</p> <p>This paragraph is styled with CSS.</p> </body> </html> ► Save Your File as css-myfirstpage.html into a new folder called CSS
  • 12. Lesson 3: Class and id Selectors  In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class". id - The id selector is used to specify a style for a single, unique element.  The id selector uses the id attribute of the HTML element, and is defined with a "#".  The style rule below will be applied to the element with id="para1":  #para1 {text-align:center;color:red;}
  • 13. Lesson 3: Class and id Selectors Class - The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements.  This allows you to set a particular style for any HTML elements with the same class.  The class selector uses the HTML class attribute, and is defined with a "."  In the example below, all HTML elements with class="center" will be center-aligned:  .center {text-align:center;}
  • 14. Lesson 3: Class and id Selectors  In the image below what is the h1 selector an ID or a Class? # .
  • 15. Lesson 3 Assignment: Let’s Create A CSS Page that uses “id” ► Open Notepad ► Type the following Code <html> <head> <style type="text/css"> #para1 { text-align:center; color:red; } </style> </head> <body> <p id="para1">Hello World!</p> <p>This paragraph is not affected by the style.</p> </body> </html> ► Save Your File as css-id.html into a your folder called CSS.
  • 16. Lesson 3 Assignment: Let’s Create A CSS Page that uses “class” ► Open Notepad ► Type the following Code <html> <head> <style type="text/css"> .center { text-align:center; } </style> </head> <body> <h1 class="center">Center-aligned heading</h1> <p class="center">Center-aligned paragraph.</p> </body> </html> ► Save Your File as css-class.html into a your folder called CSS.
  • 17. Lesson 3 Comments ► Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. ► You add comments by enclosing them in /* and */ ► Comments can span several lines, and the browser will ignore these lines. ► Example: ► /* This is a basic comment it will not appear on the page*/ /* starts the comment */ is the end of the comment /*This is a comment*/ p{ text-align:center; color:black; font-family:arial;}
  • 18. Lesson 3 Assignment: Let’s Add A Comment ► Open Your CSS-ID example in Notepad ► Type the following Code right above the style you had written previously. <html> <head> /*This is an example of how to use ID in a CSS web page*/ <style type="text/css"> #para1 { text-align:center; color:red; } </style> </head> <body> <p id="para1">Hello World!</p> <p>This paragraph is not affected by the style.</p> </body> </html> ► Save Your File as css-comment.html into a your folder called CSS.
  • 19. Lesson 4: How CSS is Applied to A Web Page ►CSS is applied to a web page using three different methods:  Inline style  Internal style sheet  External style sheet
  • 20. ►Inline CSS ►Applies styles directly to the elements by adding declarations into the style ►For Example: <p style=“color: red;”> This is a simple paragraph and the inline style makes it red.</p> Lesson 4: How CSS is Applied to A Web Page
  • 21. ► Internal Style Sheet ► Applies styles to HTML by placing the CSS rules inside the tag <style> inside the document tag <head>. ► For Example: <head> <title>my page</title> <style type=“text/css”> p{color:red}</style> </head> <body> <p>this is a simple paragraph </p> </body> Lesson 4: How CSS is Applied to A Web Page
  • 22. ► External CSS ► Applies styles as a separate file with a .css extension. The file is then referenced from inside the <head> element by a link to the file. ► For Example: <head> <title>my external style sheet page</title> <link rel=“style sheet” type=“text/css” href=“my-external- stylesheet.css”> <body> <p>this is a simple paragraph</p> </body> ► You can create an external style sheet in your text editor. Lesson 4: How CSS is Applied to A Web Page
  • 23. ► What style sheet is best? ► Web developers rarely use inline CSS. Since they prefer to not mix content with presentation. And it is not efficient since you have to declare the style individually for every component. ► Internal and External style sheets are more popular because you can style multiple elements with one rule. ► External style sheets are best because they allow you to save all the style information on a separate file from the content. You can then modify a style for a site and it will update all of the pages in a site. Lesson 4: How CSS is Applied to A Web Page
  • 24. ►CSS Colors ►In the previous lesson you have seen a few CSS styles that included color like: <p style=“color: red;”> ►There are a few ways that you can set colors in CSS: Keywords, Hex values, RGB, HSL(a) Lesson 5: Colors and Formatting in CSS
  • 25. ► CSS Colors: Keywords ► Using the keywords like: red, fuchsia, yellow, blue, green you can specify what color you would like the CSS rule to display. ► For example: ► p{color:red} ► h2{color:yellow} ► There are 17 of these keyword colors you can use in CSS. Lesson 5: Colors and Formatting in CSS
  • 26. Keyword Color Hex aqua #00ffff black #000000 blue #0000ff fuchsia #ff00ff gray #808080 green #008000 lime #00ff00 maroon #800000 navy #000080 olive #808000 orange (added in CSS 2.1) #ffa500 purple #800080 red #ff0000 silver #c0c0c0 teal #008080 white #ffffff yellow #ffff00 Lesson 5: Colors and Formatting in CSS
  • 27. ► Computers are capable of displaying a lot more than 17 colors. ► In fact they can display approximately 16.7 million colors! ► Hex Values (hex is short for hexadecimal) are the most common way of specifying colors for web pages. (see hex# in the previous chart) ► For example: p{color: #000000;} /*This is equivalent to the keyword black*/ Lesson 5: Colors and Formatting in CSS
  • 28. ►Hex numbers - has 16 possible values ►0 to 9 then A to F. Which gives you 16 values. ►RGB (Red Green Blue) has the possibility of 256 colors for each (16x16) ►(R)256 x (G)256 x (B)256 = 16,777,216 or 16.7 million color values ►CSS example: h1{color: #000000;} Lesson 5: Colors and Formatting in CSS
  • 29. ► RGB (a) can also help specify colors in CSS RGB stands for Red Green Blue ► You can specify RGB in either whole numbers or percentages ► CSS example: h1{color: rgb(0,0,0) } /*this color is equivalent to #000000 or black */ ► You use numbers from 0 to 255 which covers the 256 color range. ► More examples can be found at: http://www.w3schools.com/css/css_colors.asp Lesson 5: Colors and Formatting in CSS
  • 30. ► RGB (a) can also help specify colors in CSS RGB stands for Red Green Blue. The “a” stands for alpha but we will learn about that in another lesson. ► You can specify RGB in either whole numbers or percentages ► CSS example: h1{color: rgb(0,0,0) } /*this color is equivalent to #000000 or black */ ► You use numbers from 0 to 255 which covers the 256 color range. ► More examples can be found at: http://www.w3schools.com/css/css_colors.asp Lesson 5: Colors and Formatting in CSS
  • 31. ► HSL (a) - Hue Saturation Lightness ► Similar to RGB but based on saturation and lightness of a color ► The “a” stands for alpha but we will learn about that in another lesson. ► CSS example: h1{color: hsl(0,100%,40%) } ► HSL accepts a number between 0 to 360 in value ► HSL also accepts percentage between 0-100% Lesson 5: Colors and Formatting in CSS
  • 32. Lesson 5 Assignment: CSS Using Color ► Open Your CSS-ID example in Notepad ► Type the following Code right above the style you had written previously. <html> <body> <p style="background-color:#FFF111"> Color set by using hex value </p> <p style="background-color:rgb(0,255,0);"> Color set by using rgb value </p> <p style="background-color:red"> Color set by using color name </p> </body> </html> ► Save Your File as css-color.html into your folder called CSS
  • 33. The End ►Essential Questions Review by: Faizan Ahmed mailtofaizanahmed@gmail.com Facebook.com/pakifa