SlideShare a Scribd company logo
Selectors
Element
Type
Selector
An element type selector
matches elements with
the corresponding
element type name.
Examples
Selector {
property: value; }
 p { color: blue;}
Applies to all
elements within <p> … </p>
 div {width:50%;}
 H1 {font-family:Verdana;
Grouped
Selectors
We can group selectors
using a comma (,)
separator.
Examples
selector, selector {
property: value; }
 h1, h2, h3 { color: blue;}
Applies to all
elements within <p> … </p>
 #aydi div, p {
font-family:
Verdana}
Descendant
Selectors
The descendant selector
matches all elements that
are descendants of a
specified element.
Example
parent descendant {
property: value; }
 p em { color: blue;}
 H1 em, h2 em, h3 1m
{ color: blue;}
ID and
Class
Selectors
ID Selectors
An ID selector matches an
element that has a
specific id attribute value.
 #myline {font-
style:italic;}
 p#myline {font-
style:italic;}
Class Selectors
Class selectors matches
all elements with a class
attribute that contains
the same value.
.warning {color:red}
p.warning {color:red}
div.firstblock.warning {
color:red;}
Universal
Selector
The universal selector
matches any element
type.
*.warning and .warning
are considered equal.
* { margin: 0;
padding: 0;}
* .warning{
margin: 0;
padding: 0; }
#main * {
float: center;
}
Pseudoclass
Selectors
A pseudo-class
is used to define a
special state of an
element.
For example, it can be used
to:
 Style an element when a
user mouses over it
 Style visited and unvisited
links differently
Syntax
selector:pseudo-class {
property:value;
}
Anchor
Pseudoclass
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: blue;
}
/* mouse over link */
a:hover {
color: green;
}
/* selected link */
a:active {
color: yellow;
}
Note:
a:hover MUST come after a:link
and a:visited in the CSS
definition in order to be
effective!!
a:active MUST come after
a:hover in the CSS definition in
order to be effective!!
Pseudo-class names are not
case-sensitive.
The
::first-letter
and
::first-line
Pseudo-
element
::first-letter
Selects the first letter of
every <p> element
 p::first-letter {
color: #ff0000;
font-size: xx-large;
}
::first-line
Selects the first line of every
<p> element
 p::first-line {
color: #0000ff;
font-variant: small-caps;
}
The
::before
and
::after
Pseudoclasses
::before
The ::before pseudo-
element can be used to
insert some content before
the content of an element.
 h1::before {
content: url(smiley.gif);
}
::after
The ::after pseudo-
element can be used to
insert some content after
the content of an element.
 h1::after {
content: url(smiley.gif);
}
D.Alcalde.612@2015
Sources
 http://www.w3schools.com/css/css_pseudo_classes.as
p
 http://reference.sitepoint.com/css/classselector
 https://developer.mozilla.org/en-
US/docs/Web/CSS/Universal_selectors
 http://www.sitepoint.com/web-
foundations/descendant-selector-css-selector/

More Related Content

What's hot

html-css
html-csshtml-css
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
Prarthan P
 
HTML Semantic Tags
HTML Semantic TagsHTML Semantic Tags
HTML Semantic Tags
Bruce Kyle
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
Css Display Property
Css Display PropertyCss Display Property
Css Display Property
Webtech Learning
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
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)
Webtech Learning
 
CSS Selectors
CSS SelectorsCSS Selectors
CSS Selectors
Rachel Andrew
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
Seble Nigussie
 
CSS.ppt
CSS.pptCSS.ppt
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Propertieshstryk
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
SAMIR BHOGAYTA
 
Css selectors
Css selectorsCss selectors
Css selectors
Dinesh Kumar
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
Mario Hernandez
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
Dave Kelly
 

What's hot (20)

html-css
html-csshtml-css
html-css
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
HTML Semantic Tags
HTML Semantic TagsHTML Semantic Tags
HTML Semantic Tags
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
Css Display Property
Css Display PropertyCss Display Property
Css Display Property
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
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)
 
CSS Selectors
CSS SelectorsCSS Selectors
CSS Selectors
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
CSS.ppt
CSS.pptCSS.ppt
CSS.ppt
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Properties
 
Css box model
Css  box modelCss  box model
Css box model
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Css selectors
Css selectorsCss selectors
Css selectors
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 

Viewers also liked

Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)club23
 
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLEDEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLEVaibhav Sinha
 
Html frames
Html framesHtml frames
Html frames
nobel mujuji
 
Html frames
Html framesHtml frames
Html frames
eShikshak
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML forms
Nadine Cruz
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
jeroenvdmeer
 

Viewers also liked (7)

Html Frames
Html FramesHtml Frames
Html Frames
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
 
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLEDEFINE FRAME AND FRAME SET WITH A EXAMPLE
DEFINE FRAME AND FRAME SET WITH A EXAMPLE
 
Html frames
Html framesHtml frames
Html frames
 
Html frames
Html framesHtml frames
Html frames
 
HTML frames and HTML forms
HTML frames and HTML formsHTML frames and HTML forms
HTML frames and HTML forms
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
 

Similar to Types of Selectors (HTML)

Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
M Vishnuvardhan Reddy
 
CSS Psuedo and beyond
CSS Psuedo and beyondCSS Psuedo and beyond
CSS Psuedo and beyond
mkivikoski
 
css-ppt.pdf
css-ppt.pdfcss-ppt.pdf
css-ppt.pdf
EktaDesai14
 
CSS3 and Selectors
CSS3 and SelectorsCSS3 and Selectors
CSS3 and Selectors
Rachel Andrew
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
Hatem Mahmoud
 
CSS selectors
CSS selectorsCSS selectors
CSS selectors
Héla Ben Khalfallah
 
HTML and CSS part 2
HTML and CSS part 2HTML and CSS part 2
HTML and CSS part 2
Julie Iskander
 
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)
Ardee Aram
 
Web engineering
Web engineeringWeb engineering
Web engineering
Syed Nouman Ali Shah
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7
phuphax
 

Similar to Types of Selectors (HTML) (20)

Css class-02
Css class-02Css class-02
Css class-02
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Css advanced – session 5
Css advanced – session 5Css advanced – session 5
Css advanced – session 5
 
Css
CssCss
Css
 
Css
CssCss
Css
 
CSS Psuedo and beyond
CSS Psuedo and beyondCSS Psuedo and beyond
CSS Psuedo and beyond
 
Basic css
Basic cssBasic css
Basic css
 
css-ppt.pdf
css-ppt.pdfcss-ppt.pdf
css-ppt.pdf
 
CSS3 and Selectors
CSS3 and SelectorsCSS3 and Selectors
CSS3 and Selectors
 
Pseudo CSS Selectors
Pseudo CSS SelectorsPseudo CSS Selectors
Pseudo CSS Selectors
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Css
CssCss
Css
 
CSS selectors
CSS selectorsCSS selectors
CSS selectors
 
HTML and CSS part 2
HTML and CSS part 2HTML and CSS part 2
HTML and CSS part 2
 
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)
 
CSS
CSSCSS
CSS
 
3. CSS
3. CSS3. CSS
3. CSS
 
Web engineering
Web engineeringWeb engineering
Web engineering
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7
 

More from Deanne Alcalde

Sexuality
SexualitySexuality
Sexuality
Deanne Alcalde
 
Marital practices (accross cultures)
Marital practices (accross cultures)Marital practices (accross cultures)
Marital practices (accross cultures)
Deanne Alcalde
 
Vascular Tissue
Vascular TissueVascular Tissue
Vascular Tissue
Deanne Alcalde
 
Anglo-Saxons
Anglo-SaxonsAnglo-Saxons
Anglo-Saxons
Deanne Alcalde
 
Functional Speaking
Functional SpeakingFunctional Speaking
Functional Speaking
Deanne Alcalde
 
Chinese Traditional Music (School Presentation 2013)
Chinese Traditional Music (School Presentation 2013)Chinese Traditional Music (School Presentation 2013)
Chinese Traditional Music (School Presentation 2013)
Deanne Alcalde
 

More from Deanne Alcalde (6)

Sexuality
SexualitySexuality
Sexuality
 
Marital practices (accross cultures)
Marital practices (accross cultures)Marital practices (accross cultures)
Marital practices (accross cultures)
 
Vascular Tissue
Vascular TissueVascular Tissue
Vascular Tissue
 
Anglo-Saxons
Anglo-SaxonsAnglo-Saxons
Anglo-Saxons
 
Functional Speaking
Functional SpeakingFunctional Speaking
Functional Speaking
 
Chinese Traditional Music (School Presentation 2013)
Chinese Traditional Music (School Presentation 2013)Chinese Traditional Music (School Presentation 2013)
Chinese Traditional Music (School Presentation 2013)
 

Recently uploaded

Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

Types of Selectors (HTML)

  • 2. Element Type Selector An element type selector matches elements with the corresponding element type name. Examples Selector { property: value; }  p { color: blue;} Applies to all elements within <p> … </p>  div {width:50%;}  H1 {font-family:Verdana;
  • 3. Grouped Selectors We can group selectors using a comma (,) separator. Examples selector, selector { property: value; }  h1, h2, h3 { color: blue;} Applies to all elements within <p> … </p>  #aydi div, p { font-family: Verdana}
  • 4. Descendant Selectors The descendant selector matches all elements that are descendants of a specified element. Example parent descendant { property: value; }  p em { color: blue;}  H1 em, h2 em, h3 1m { color: blue;}
  • 5. ID and Class Selectors ID Selectors An ID selector matches an element that has a specific id attribute value.  #myline {font- style:italic;}  p#myline {font- style:italic;} Class Selectors Class selectors matches all elements with a class attribute that contains the same value. .warning {color:red} p.warning {color:red} div.firstblock.warning { color:red;}
  • 6. Universal Selector The universal selector matches any element type. *.warning and .warning are considered equal. * { margin: 0; padding: 0;} * .warning{ margin: 0; padding: 0; } #main * { float: center; }
  • 7. Pseudoclass Selectors A pseudo-class is used to define a special state of an element. For example, it can be used to:  Style an element when a user mouses over it  Style visited and unvisited links differently Syntax selector:pseudo-class { property:value; }
  • 8. Anchor Pseudoclass /* unvisited link */ a:link { color: red; } /* visited link */ a:visited { color: blue; } /* mouse over link */ a:hover { color: green; } /* selected link */ a:active { color: yellow; } Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective!! a:active MUST come after a:hover in the CSS definition in order to be effective!! Pseudo-class names are not case-sensitive.
  • 9. The ::first-letter and ::first-line Pseudo- element ::first-letter Selects the first letter of every <p> element  p::first-letter { color: #ff0000; font-size: xx-large; } ::first-line Selects the first line of every <p> element  p::first-line { color: #0000ff; font-variant: small-caps; }
  • 10. The ::before and ::after Pseudoclasses ::before The ::before pseudo- element can be used to insert some content before the content of an element.  h1::before { content: url(smiley.gif); } ::after The ::after pseudo- element can be used to insert some content after the content of an element.  h1::after { content: url(smiley.gif); } D.Alcalde.612@2015
  • 11. Sources  http://www.w3schools.com/css/css_pseudo_classes.as p  http://reference.sitepoint.com/css/classselector  https://developer.mozilla.org/en- US/docs/Web/CSS/Universal_selectors  http://www.sitepoint.com/web- foundations/descendant-selector-css-selector/