Id and class selector
Upcoming SlideShare
Loading in...5

Id and class selector






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Id and class selector Id and class selector Presentation Transcript

  • Unit III: Adding Styles andInteractivity 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! Itwill 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 FOLLOWINGUse para1 and para2 as ID, then use “h’ and “i” as class selector.LAY-OUTParagraph 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)CONTENT1st paragraph: Honesty is the best policy2nd 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>
  • ANSWERp.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>