SlideShare a Scribd company logo
1 of 8
Unit III: Adding Styles and
Interactivity Using CSS and
           Javascript
The id Selectors

• In addition to setting a style for a HTML
  element, CSS allows you to specify your own
  selectors called "id" and "class".
• The id Selector
• 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 "#".
Example
<style type= “text/css”
#para1{text-align: center; color: red;}
#para2{text-align: left; color: green;}
</style>
<p id= “para1”>Hello World</p>
<p id= “para2”>Hello Philippines</p>

Do NOT start an ID name with a number! It
will not work in Mozilla/Firefox.
The class Selector
• 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
  many HTML elements with the same class.
• The class selector uses the HTML class
  attribute, and is defined with a "."
EXAMPLE
<style type= “text/css”
p.a {background-color: red text-align: center;}
p.b {background-color: green text-align: left;}
p.c {background-color: blue text-align: right;}
</style>
<p class= “a”>Hello World</p>
<p class= “b”>Hello World</p>
<p class= “c”>Hello World</p>
APPLY THE ID and CLASS SELECTOR
         FOR THE FOLLOWING
Use para1 and para2 as ID, then use “h’ and “i” as
   class selector.
LAY-OUT
Paragraph 1. (background blue, foreground is red,
   font face is Aharoni, font size is 10 pixels)
Paragraph 2. (background green, foreground is
   white, font face is Batang, font size is 15 pixels)
CONTENT
1st paragraph: Honesty is the best policy
2nd paragraph: Health and wealth.
ANSWER
#para1{background-color: blue; color: red; font-
  family: Aharoni; font-size: 10px;}
#para2{background-color: green; color: white;
  font-family: Batang; font-size: 15px;}
</style>
<p id= “para1”>Honesty is the best policy</p>
<p id= “para2”>Health is wealth</p>
ANSWER
p.h{background-color: blue; color: red; font-
  family: Aharoni; font-size: 10px;}
p.i{background-color: green; color: white; font-
  family: Batang; font-size: 15px;}
</style>
<p class= “h”>Honesty is the best policy</p>
<p class= “i”>Health is wealth</p>

More Related Content

What's hot

What's hot (20)

Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
 
html-css
html-csshtml-css
html-css
 
1 03 - CSS Introduction
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introduction
 
HTML Text formatting tags
HTML Text formatting tagsHTML Text formatting tags
HTML Text formatting tags
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 
Css ppt
Css pptCss ppt
Css ppt
 
Css Basics
Css BasicsCss Basics
Css Basics
 
Dtd
DtdDtd
Dtd
 
CSS
CSSCSS
CSS
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Properties
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
 
CSS notes
CSS notesCSS notes
CSS notes
 
Advanced Cascading Style Sheets
Advanced Cascading Style SheetsAdvanced Cascading Style Sheets
Advanced Cascading Style Sheets
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
CSS media types
CSS media typesCSS media types
CSS media types
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
CSS
CSSCSS
CSS
 
Web design - Working with tables in HTML
Web design - Working with tables in HTMLWeb design - Working with tables in HTML
Web design - Working with tables in HTML
 
Css types internal, external and inline (1)
Css types internal, external and inline (1)Css types internal, external and inline (1)
Css types internal, external and inline (1)
 

Viewers also liked

Designing web pages html forms and input
Designing web pages html  forms and inputDesigning web pages html  forms and input
Designing web pages html forms and inputJesus Obenita Jr.
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operatorsJesus Obenita Jr.
 
Css border and outline properties
Css border and outline propertiesCss border and outline properties
Css border and outline propertiesJesus Obenita Jr.
 
Web browser, linux, bit & bytes, files
Web browser, linux, bit & bytes, filesWeb browser, linux, bit & bytes, files
Web browser, linux, bit & bytes, filesJesus Obenita Jr.
 
Designing web page marquee and img tag
Designing web page  marquee and img tagDesigning web page  marquee and img tag
Designing web page marquee and img tagJesus Obenita Jr.
 

Viewers also liked (8)

Css external style sheet
Css external style sheetCss external style sheet
Css external style sheet
 
Designing web pages html forms and input
Designing web pages html  forms and inputDesigning web pages html  forms and input
Designing web pages html forms and input
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
 
Css border and outline properties
Css border and outline propertiesCss border and outline properties
Css border and outline properties
 
Web browser, linux, bit & bytes, files
Web browser, linux, bit & bytes, filesWeb browser, linux, bit & bytes, files
Web browser, linux, bit & bytes, files
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
Picasa&gimp v2.0
Picasa&gimp v2.0Picasa&gimp v2.0
Picasa&gimp v2.0
 
Designing web page marquee and img tag
Designing web page  marquee and img tagDesigning web page  marquee and img tag
Designing web page marquee and img tag
 

Similar to Id and class selector

Similar to Id and class selector (20)

Make Css easy : easy tips for css
Make Css easy : easy tips for cssMake Css easy : easy tips for css
Make Css easy : easy tips for css
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
 
Html html html html html html html html html
Html html html html html html html html htmlHtml html html html html html html html html
Html html html html html html html html html
 
Lec 1
Lec 1Lec 1
Lec 1
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
Css
CssCss
Css
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
TM 1st quarter - 4th meeting
TM   1st quarter - 4th meetingTM   1st quarter - 4th meeting
TM 1st quarter - 4th meeting
 
CSS.pdf
CSS.pdfCSS.pdf
CSS.pdf
 
6_CasCadingStylesSheetsCSS.ppt
6_CasCadingStylesSheetsCSS.ppt6_CasCadingStylesSheetsCSS.ppt
6_CasCadingStylesSheetsCSS.ppt
 
Html advance
Html advanceHtml advance
Html advance
 
HTML-Advance.pptx
HTML-Advance.pptxHTML-Advance.pptx
HTML-Advance.pptx
 
Html 2
Html   2Html   2
Html 2
 
Css 1
Css 1Css 1
Css 1
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Web Designing
Web DesigningWeb Designing
Web Designing
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
Turorial css
Turorial cssTurorial css
Turorial css
 
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
 

More from Jesus Obenita Jr.

More from Jesus Obenita Jr. (20)

Organization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management TheoryOrganization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management Theory
 
Organization and management 2 Management Function
Organization and management 2 Management FunctionOrganization and management 2 Management Function
Organization and management 2 Management Function
 
Organization and management 1
Organization and management 1Organization and management 1
Organization and management 1
 
Ms excel 2013 formatting worksheets
Ms excel 2013 formatting worksheetsMs excel 2013 formatting worksheets
Ms excel 2013 formatting worksheets
 
Ms excel 2013 data management
Ms excel 2013 data managementMs excel 2013 data management
Ms excel 2013 data management
 
Microsoft Excel introduction
Microsoft Excel introductionMicrosoft Excel introduction
Microsoft Excel introduction
 
Word 2013 working with pictures
Word 2013 working with picturesWord 2013 working with pictures
Word 2013 working with pictures
 
Word 2013 Formatting Page
Word 2013 Formatting PageWord 2013 Formatting Page
Word 2013 Formatting Page
 
Word 2013 8
Word 2013 8Word 2013 8
Word 2013 8
 
Ms word 2013 7
Ms word 2013 7Ms word 2013 7
Ms word 2013 7
 
Ms word 2013 6
Ms word 2013 6Ms word 2013 6
Ms word 2013 6
 
Ms word 2013 4
Ms word 2013 4Ms word 2013 4
Ms word 2013 4
 
Ms word 2013 2
Ms word 2013 2Ms word 2013 2
Ms word 2013 2
 
Ms word 2013
Ms word 2013Ms word 2013
Ms word 2013
 
Parts of the ms word 2013 screen and
Parts of the ms word 2013 screen andParts of the ms word 2013 screen and
Parts of the ms word 2013 screen and
 
Word processor
Word processorWord processor
Word processor
 
Session 2 test construction.mt's
Session 2   test construction.mt'sSession 2   test construction.mt's
Session 2 test construction.mt's
 
Cooking ingredients
Cooking ingredientsCooking ingredients
Cooking ingredients
 
Color theory
Color theoryColor theory
Color theory
 
Computer software
Computer softwareComputer software
Computer software
 

Id and class selector

  • 1. Unit III: Adding Styles and Interactivity Using CSS and Javascript
  • 2. The id Selectors • In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class". • The id Selector • 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 "#".
  • 3. Example <style type= “text/css” #para1{text-align: center; color: red;} #para2{text-align: left; color: green;} </style> <p id= “para1”>Hello World</p> <p id= “para2”>Hello Philippines</p> Do NOT start an ID name with a number! It will not work in Mozilla/Firefox.
  • 4. The class Selector • 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 many HTML elements with the same class. • The class selector uses the HTML class attribute, and is defined with a "."
  • 5. EXAMPLE <style type= “text/css” p.a {background-color: red text-align: center;} p.b {background-color: green text-align: left;} p.c {background-color: blue text-align: right;} </style> <p class= “a”>Hello World</p> <p class= “b”>Hello World</p> <p class= “c”>Hello World</p>
  • 6. APPLY THE ID and CLASS SELECTOR FOR THE FOLLOWING Use para1 and para2 as ID, then use “h’ and “i” as class selector. LAY-OUT Paragraph 1. (background blue, foreground is red, font face is Aharoni, font size is 10 pixels) Paragraph 2. (background green, foreground is white, font face is Batang, font size is 15 pixels) CONTENT 1st paragraph: Honesty is the best policy 2nd paragraph: Health and wealth.
  • 7. ANSWER #para1{background-color: blue; color: red; font- family: Aharoni; font-size: 10px;} #para2{background-color: green; color: white; font-family: Batang; font-size: 15px;} </style> <p id= “para1”>Honesty is the best policy</p> <p id= “para2”>Health is wealth</p>
  • 8. ANSWER p.h{background-color: blue; color: red; font- family: Aharoni; font-size: 10px;} p.i{background-color: green; color: white; font- family: Batang; font-size: 15px;} </style> <p class= “h”>Honesty is the best policy</p> <p class= “i”>Health is wealth</p>