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 (20)

Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
DataFrame in Python Pandas
DataFrame in Python PandasDataFrame in Python Pandas
DataFrame in Python Pandas
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
Formatting tags
Formatting tagsFormatting tags
Formatting tags
 
Hyperlinks in HTML
Hyperlinks in HTMLHyperlinks in HTML
Hyperlinks in HTML
 
Css pseudo-classes
Css pseudo-classesCss pseudo-classes
Css pseudo-classes
 
Html forms
Html formsHtml forms
Html forms
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Basic html structure
Basic html structureBasic html structure
Basic html structure
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
Html tables, forms and audio video
Html tables, forms and audio videoHtml tables, forms and audio video
Html tables, forms and audio video
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTML
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV Connectivity
 
SQL Queries - DDL Commands
SQL Queries - DDL CommandsSQL Queries - DDL Commands
SQL Queries - DDL Commands
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting data
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 

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 Basics
Css BasicsCss Basics
Css Basics
 
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
 

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>