SlideShare uma empresa 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.

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

Destaque (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
 

Semelhante a Castro Chapter 9

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)
Thinkful
 

Semelhante 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)
 

Mais de Jeff Byrnes

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

Mais 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

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Último (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
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
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

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.