SlideShare una empresa de Scribd logo
1 de 10
DEFINING SELECTORS
HTML5 & CSS Visual Quickstart Guide
Chapter 9
Constructing Selectors
• The selector determines which elements a style rule
  applies to
• A selector can define up to 5 different criteria for choosing
  the elements that should be formatted:
  • Type or name of the element
  • Context in which element is found
  • Class or id of an element
  • Pseudo-class of an element or a pseudo-element itself
  • Whether or not an element has certain attributes or values
Selecting Elements by Name
• Type selector, where selector is the name of the desired
 type of element, without any attributes
  • p
  • h1
  • a
Selecting Elements by Context
• Type ancestor, where ancestor is the name of the
  element containing the element you wish to format
• Type a space
• Type descendant, where descendant is the name of the
  element you wish to format
• Example:
 • h1 em { color: red; }
 • Would find any em element within an h1 element and color it red
Selecting Elements by ID or Class
• To select based on class
   • Type . (period) followed by the class, without any spaces
   • Example:
     • .very { color: red; }
     • Will choose any element with class=“very” in its HTML start tag and
       color it red
• To select based on id:
   • Type # followed by the id, without any spaces
   • Example:
     • #gaudi {color:red;}
     • Will choose any element with an id equal to “gaudi,” and color
       everything within that element red
More on ID and Class
• Can be more specific by prefixing class or id selector with
  element name to target
• Example:
  • em.very { color: red; }
  • Will select only those em elements that have class=“very” in their
   starting HTML tags, and color them red
Selecting Elements Based on Their
Parent
• Type parent, where parent is the element that directly
  contains the element you wish to format
• Type > (the greater than sign)
• Type child, where child is the name of the element you
  wish to format
• Example:
  • div#gaudi > p {color:red;}
  • Will choose only those p elements that are children of the gaudi div.
   They may not be contained within any other element, or they do not
   qualify for this rule.
Selecting Part of an Element
• Use pseudo-elements first-letter, first-line, etc.
• Examples:
  • p:first-line {color:red;}
     • Would color the first line of the paragraph red, but all other lines would
       be the default color (black, unless defined otherwise)
  • p:first-letter {color:red;}
     • Would color the first letter of the paragraph red, but the rest of the
       paragraph would be the default color (black, unless defined otherwise)
Selecting Link Elements Based on Their
State
• Useful for changing the default color of links
• Example:
  • a:link {color:red;}
    a:visited {color:orange;}
    a:focus {color:purple;}
    a:hover {color:green;}
    a:active {color:blue;}
  • Would cause the following text effects:
    • New, not visited links will be red
    • Once the link has been visited, it turns orange
    • If the link gets focus, as by Tabbing to it, it turns purple
    • If the visitor hovers over the link with the mouse, it turns green
    • As the visitor clicks the link, it turns purple
Specifying Groups of Selectors
• Occasionally want to set the same attributes to several
  elements
• Example:
  • h1, h2 {color:red;}
  • Will set color of both h1 and h2 elements to red.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Web Development - Lecture 5
Web Development - Lecture 5Web Development - Lecture 5
Web Development - Lecture 5
 
23xml
23xml23xml
23xml
 
Web Development - Lecture 3
Web Development - Lecture 3Web Development - Lecture 3
Web Development - Lecture 3
 
Dtd
DtdDtd
Dtd
 
SFDC Database Basics
SFDC Database BasicsSFDC Database Basics
SFDC Database Basics
 
Xml
XmlXml
Xml
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Web Development - Lecture 6
Web Development - Lecture 6Web Development - Lecture 6
Web Development - Lecture 6
 
Java – lexical issues
Java – lexical issuesJava – lexical issues
Java – lexical issues
 
Ch2 neworder
Ch2 neworderCh2 neworder
Ch2 neworder
 
Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML Form
 
Web Development - Lecture 2
Web Development - Lecture 2Web Development - Lecture 2
Web Development - Lecture 2
 
Xml dtd- Document Type Definition- Web Technology
Xml dtd- Document Type Definition- Web TechnologyXml dtd- Document Type Definition- Web Technology
Xml dtd- Document Type Definition- Web Technology
 
Gitika html ppt
Gitika html pptGitika html ppt
Gitika html ppt
 
Web Engineering - Introduction to CSS
Web Engineering - Introduction to CSSWeb Engineering - Introduction to CSS
Web Engineering - Introduction to CSS
 
Xml dom
Xml domXml dom
Xml dom
 
PHP | ZENUS INFOTECH INDIA PVT. LTD.
PHP | ZENUS INFOTECH INDIA PVT. LTD. PHP | ZENUS INFOTECH INDIA PVT. LTD.
PHP | ZENUS INFOTECH INDIA PVT. LTD.
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)
 
Forms Part 1
Forms Part 1Forms Part 1
Forms Part 1
 

Destacado

Financial analysis pp
Financial analysis ppFinancial analysis pp
Financial analysis ppJoeVelarde
 
INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1Jeff Byrnes
 
Castro Chapter 4
Castro Chapter 4Castro Chapter 4
Castro Chapter 4Jeff Byrnes
 
Castro Chapter 6
Castro Chapter 6Castro Chapter 6
Castro Chapter 6Jeff Byrnes
 
Castro Chapter 3
Castro Chapter 3Castro Chapter 3
Castro Chapter 3Jeff Byrnes
 
Castro Chapter 5
Castro Chapter 5Castro Chapter 5
Castro Chapter 5Jeff Byrnes
 
INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2Jeff Byrnes
 
Castro Chapter 15
Castro Chapter 15Castro Chapter 15
Castro Chapter 15Jeff Byrnes
 
Handbook of laying pipe sp57
Handbook of laying pipe sp57Handbook of laying pipe sp57
Handbook of laying pipe sp57Yogesh Nema
 

Destacado (9)

Financial analysis pp
Financial analysis ppFinancial analysis pp
Financial analysis pp
 
INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1INFO 3775 Chapter 2 Part 1
INFO 3775 Chapter 2 Part 1
 
Castro Chapter 4
Castro Chapter 4Castro Chapter 4
Castro Chapter 4
 
Castro Chapter 6
Castro Chapter 6Castro Chapter 6
Castro Chapter 6
 
Castro Chapter 3
Castro Chapter 3Castro Chapter 3
Castro Chapter 3
 
Castro Chapter 5
Castro Chapter 5Castro Chapter 5
Castro Chapter 5
 
INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2
 
Castro Chapter 15
Castro Chapter 15Castro Chapter 15
Castro Chapter 15
 
Handbook of laying pipe sp57
Handbook of laying pipe sp57Handbook of laying pipe sp57
Handbook of laying pipe sp57
 

Similar a Castro Chapter 9 (20)

CSS Overview and Examples
CSS Overview and ExamplesCSS Overview and Examples
CSS Overview and Examples
 
Lecture2 CSS 2
Lecture2  CSS 2Lecture2  CSS 2
Lecture2 CSS 2
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
Basic css-tutorial
Basic css-tutorialBasic css-tutorial
Basic css-tutorial
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
Basic css
Basic cssBasic css
Basic css
 
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
 
Web Design & Development - Session 2
Web Design & Development - Session 2Web Design & Development - Session 2
Web Design & Development - Session 2
 
Css syntax
Css   syntaxCss   syntax
Css syntax
 
Code & Design your first website 4/18
Code & Design your first website 4/18Code & Design your first website 4/18
Code & Design your first website 4/18
 
Html
HtmlHtml
Html
 
Types of Selectors (HTML)
Types of Selectors (HTML)Types of Selectors (HTML)
Types of Selectors (HTML)
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Basic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdfBasic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdf
 
Html,javascript & css
Html,javascript & cssHtml,javascript & css
Html,javascript & css
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
 
9781111528705_PPT_ch04.ppt
9781111528705_PPT_ch04.ppt9781111528705_PPT_ch04.ppt
9781111528705_PPT_ch04.ppt
 
Html
HtmlHtml
Html
 
Css class-02
Css class-02Css class-02
Css class-02
 
Code & design your first website (3:16)
Code & design your first website (3:16)Code & design your first website (3:16)
Code & design your first website (3:16)
 

Más de Jeff Byrnes

Castro Chapter 11
Castro Chapter 11Castro Chapter 11
Castro Chapter 11Jeff Byrnes
 
Castro Chapter 10
Castro Chapter 10Castro Chapter 10
Castro Chapter 10Jeff Byrnes
 
Castro Chapter 8
Castro Chapter 8Castro Chapter 8
Castro Chapter 8Jeff Byrnes
 
Castro Chapter 7
Castro Chapter 7Castro Chapter 7
Castro Chapter 7Jeff Byrnes
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2Jeff Byrnes
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2Jeff Byrnes
 

Más de Jeff Byrnes (6)

Castro Chapter 11
Castro Chapter 11Castro Chapter 11
Castro Chapter 11
 
Castro Chapter 10
Castro Chapter 10Castro Chapter 10
Castro Chapter 10
 
Castro Chapter 8
Castro Chapter 8Castro Chapter 8
Castro Chapter 8
 
Castro Chapter 7
Castro Chapter 7Castro Chapter 7
Castro Chapter 7
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Último (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Castro Chapter 9

  • 1. DEFINING SELECTORS HTML5 & CSS Visual Quickstart Guide Chapter 9
  • 2. Constructing Selectors • The selector determines which elements a style rule applies to • A selector can define up to 5 different criteria for choosing the elements that should be formatted: • Type or name of the element • Context in which element is found • Class or id of an element • Pseudo-class of an element or a pseudo-element itself • Whether or not an element has certain attributes or values
  • 3. Selecting Elements by Name • Type selector, where selector is the name of the desired type of element, without any attributes • p • h1 • a
  • 4. Selecting Elements by Context • Type ancestor, where ancestor is the name of the element containing the element you wish to format • Type a space • Type descendant, where descendant is the name of the element you wish to format • Example: • h1 em { color: red; } • Would find any em element within an h1 element and color it red
  • 5. Selecting Elements by ID or Class • To select based on class • Type . (period) followed by the class, without any spaces • Example: • .very { color: red; } • Will choose any element with class=“very” in its HTML start tag and color it red • To select based on id: • Type # followed by the id, without any spaces • Example: • #gaudi {color:red;} • Will choose any element with an id equal to “gaudi,” and color everything within that element red
  • 6. More on ID and Class • Can be more specific by prefixing class or id selector with element name to target • Example: • em.very { color: red; } • Will select only those em elements that have class=“very” in their starting HTML tags, and color them red
  • 7. Selecting Elements Based on Their Parent • Type parent, where parent is the element that directly contains the element you wish to format • Type > (the greater than sign) • Type child, where child is the name of the element you wish to format • Example: • div#gaudi > p {color:red;} • Will choose only those p elements that are children of the gaudi div. They may not be contained within any other element, or they do not qualify for this rule.
  • 8. Selecting Part of an Element • Use pseudo-elements first-letter, first-line, etc. • Examples: • p:first-line {color:red;} • Would color the first line of the paragraph red, but all other lines would be the default color (black, unless defined otherwise) • p:first-letter {color:red;} • Would color the first letter of the paragraph red, but the rest of the paragraph would be the default color (black, unless defined otherwise)
  • 9. Selecting Link Elements Based on Their State • Useful for changing the default color of links • Example: • a:link {color:red;} a:visited {color:orange;} a:focus {color:purple;} a:hover {color:green;} a:active {color:blue;} • Would cause the following text effects: • New, not visited links will be red • Once the link has been visited, it turns orange • If the link gets focus, as by Tabbing to it, it turns purple • If the visitor hovers over the link with the mouse, it turns green • As the visitor clicks the link, it turns purple
  • 10. Specifying Groups of Selectors • Occasionally want to set the same attributes to several elements • Example: • h1, h2 {color:red;} • Will set color of both h1 and h2 elements to red.