SlideShare a Scribd company logo
1 of 17
(Cascaded Style Sheet Selectors)
Tutorial On
Insert Your Image Here!!
By:
(Dinesh Kumar)
PGT(Computer Science, DPS Bareilly)
A CSS selector is the part of a CSS rule set that actually selects the
content you want to style.
Universal Selector
Element Type Selector
ID Selector
Class Selector
Descendant Combinator
Child Combinator
Adjacent Sibling Combinator
Attribute Selector
Pseudo-class
CSS selector Types
The universal selector represented by symbol (*)
works like a wild card character, selecting all elements
on a page.
The three lines of code inside the curly braces
(color, font-size, and line-height) will apply to all
elements on the HTML page
Universal Selector
*{
color: green;
font-size: 20px;
line-height: 25px;
}
Also referred to as a “type selector,” this selector must
match one or more HTML elements of the same
name.
The following example uses an element type selector
to match all <ul> elements:
Element Type Selector
ul
{
list-style: none;
border: solid 1px #ccc;
}
An ID selector is declared using a hash, or pound symbol (#).
This selector matches any HTML element that has an ID
attribute with the same value as that of the selector, but
minus the hash symbol.
This CSS uses an ID selector to match an HTML element such
as:
ID Selector
#container
{
width: 960px;
margin: 0 auto;
}
<div id="container">………</div>
The class selector is the most useful of all CSS selectors.
The class selector matches all elements on the page that have
their class attribute set to the same value as the class
selector.
These styles will apply to the following HTML element:
<div class="box"></div>
Class Selector
.box
{
padding: 20px;
margin: 10px;
width: 240px;
}
The descendant combinator lets you combine two or more
selectors so you can be more specific in your selection
method.
This declaration block will apply to all elements that have a
class of box that are inside an element with an ID
of container.
Example:
<div id="container">
<div class="box">…..</div>
</div>
Descendant Combinator
#container .box
{
float: left;
padding-bottom: 15px;
}
A selector that uses the child combinator is similar to a
selector that uses a descendant combinator, except it
only targets immediate child elements.
This is the same code from the descendant combinator,
but instead of a space character, we’re using the
greater-than symbol.
Child Combinator
#container > .box
{
float: left;
padding-bottom: 15px;
}
A selector that uses the adjacent sibling combinator uses
the (+) symbol, and is almost the same as the general
sibling selector. The difference is that the targeted
element must be an immediate sibling, not just a
general sibling.
Adjacent Sibling Combinator
p + p
{
text-indent: 1.5em;
margin-bottom: 0;
}
The attribute selector targets elements based on the
presence of HTML attributes, and is declared using
square brackets:
The above CSS would match the following element:
<input type="text">
Attribute Selector
input[type="text"]
{
background-color: #444;
width: 200px;
}
The attribute selector can also be declared using just the
attribute itself, with no value, like this:
This will match all input elements with an attribute
of type, regardless of the value.
Attribute Selector…
input[type]
{
background-color: #444;
width: 200px;
}
A pseudo-class uses a colon character to identify a
pseudo-state that an element might be in—for
example, the state of being hovered, or the state of
being activated.
This means that when the user hovers their mouse over
an element, the color property for that element will change
to red.
Pseudo-class
a:hover
{
color: red;
}
Some of the most frequently used pseudo-classes are as
follows:
:first-child pseudo-class
The :first-child pseudo-class matches an element that is the
first child element of some other element.
Pseudo-class…
div > p:first-child
{
text-indent: 0
}
The link pseudo-classes: :link and :visited
• The :link pseudo-class applies for links that have not
yet been visited.
• The :visited pseudo-class applies once the link has
been visited by the user.
Pseudo-class…
a:link { color: blue }
a:visited { color: purple }
The dynamic pseudo-classes: :hover, :active,
and :focus
• The :hover pseudo-class applies while the user
designates an element (with some pointing device),
but does not activate it.
• The :active pseudo-class applies while an element is
being activated by the user.
• The :focus pseudo-class applies while an element has
the focus (accepts keyboard events or other forms of
text input).
Pseudo-class…
Pseudo-class…
The last selector matches A elements that are in pseudo-
class :focus and in pseudo-class :hover.
a:link { color: red } /* unvisited links */
a:visited { color: blue } /* visited links */
a:hover { color: yellow } /* user hovers */
a:active { color: lime } /* active links */
a:focus { background: yellow }
a:focus:hover { background: white }
CSS Selectors Guide

More Related Content

What's hot (20)

CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
Html and css
Html and cssHtml and css
Html and css
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
Css
CssCss
Css
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
Css
CssCss
Css
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
CSS
CSSCSS
CSS
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
 
html-table
html-tablehtml-table
html-table
 
Css
CssCss
Css
 
Css selectors
Css selectorsCss selectors
Css selectors
 
html-css
html-csshtml-css
html-css
 
CSS
CSSCSS
CSS
 

Similar to CSS Selectors Guide

Similar to CSS Selectors Guide (20)

Introducing CSS Selectors.docx
Introducing CSS Selectors.docxIntroducing CSS Selectors.docx
Introducing CSS Selectors.docx
 
Css class-02
Css class-02Css class-02
Css class-02
 
Lesson 3 - HTML & CSS Part 2
Lesson 3 - HTML & CSS Part 2Lesson 3 - HTML & CSS Part 2
Lesson 3 - HTML & CSS Part 2
 
Web 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style SheetsWeb 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style Sheets
 
3-CSS_essentials.ppt
3-CSS_essentials.ppt3-CSS_essentials.ppt
3-CSS_essentials.ppt
 
3-CSS_essentials_developers_begineers.ppt
3-CSS_essentials_developers_begineers.ppt3-CSS_essentials_developers_begineers.ppt
3-CSS_essentials_developers_begineers.ppt
 
3-CSS_essentials.ppt
3-CSS_essentials.ppt3-CSS_essentials.ppt
3-CSS_essentials.ppt
 
Lecture2 CSS 2
Lecture2  CSS 2Lecture2  CSS 2
Lecture2 CSS 2
 
Types of Selectors (HTML)
Types of Selectors (HTML)Types of Selectors (HTML)
Types of Selectors (HTML)
 
CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2
 
3 css essentials
3 css essentials3 css essentials
3 css essentials
 
Designing for the web - 101
Designing for the web - 101Designing for the web - 101
Designing for the web - 101
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
 
Basic css
Basic cssBasic css
Basic css
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
CSS
CSSCSS
CSS
 
Introduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and JqueryIntroduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and Jquery
 
Css Selectors
Css SelectorsCss Selectors
Css Selectors
 
Css3
Css3Css3
Css3
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

CSS Selectors Guide

  • 1. (Cascaded Style Sheet Selectors) Tutorial On Insert Your Image Here!! By: (Dinesh Kumar) PGT(Computer Science, DPS Bareilly)
  • 2. A CSS selector is the part of a CSS rule set that actually selects the content you want to style. Universal Selector Element Type Selector ID Selector Class Selector Descendant Combinator Child Combinator Adjacent Sibling Combinator Attribute Selector Pseudo-class CSS selector Types
  • 3. The universal selector represented by symbol (*) works like a wild card character, selecting all elements on a page. The three lines of code inside the curly braces (color, font-size, and line-height) will apply to all elements on the HTML page Universal Selector *{ color: green; font-size: 20px; line-height: 25px; }
  • 4. Also referred to as a “type selector,” this selector must match one or more HTML elements of the same name. The following example uses an element type selector to match all <ul> elements: Element Type Selector ul { list-style: none; border: solid 1px #ccc; }
  • 5. An ID selector is declared using a hash, or pound symbol (#). This selector matches any HTML element that has an ID attribute with the same value as that of the selector, but minus the hash symbol. This CSS uses an ID selector to match an HTML element such as: ID Selector #container { width: 960px; margin: 0 auto; } <div id="container">………</div>
  • 6. The class selector is the most useful of all CSS selectors. The class selector matches all elements on the page that have their class attribute set to the same value as the class selector. These styles will apply to the following HTML element: <div class="box"></div> Class Selector .box { padding: 20px; margin: 10px; width: 240px; }
  • 7. The descendant combinator lets you combine two or more selectors so you can be more specific in your selection method. This declaration block will apply to all elements that have a class of box that are inside an element with an ID of container. Example: <div id="container"> <div class="box">…..</div> </div> Descendant Combinator #container .box { float: left; padding-bottom: 15px; }
  • 8. A selector that uses the child combinator is similar to a selector that uses a descendant combinator, except it only targets immediate child elements. This is the same code from the descendant combinator, but instead of a space character, we’re using the greater-than symbol. Child Combinator #container > .box { float: left; padding-bottom: 15px; }
  • 9. A selector that uses the adjacent sibling combinator uses the (+) symbol, and is almost the same as the general sibling selector. The difference is that the targeted element must be an immediate sibling, not just a general sibling. Adjacent Sibling Combinator p + p { text-indent: 1.5em; margin-bottom: 0; }
  • 10. The attribute selector targets elements based on the presence of HTML attributes, and is declared using square brackets: The above CSS would match the following element: <input type="text"> Attribute Selector input[type="text"] { background-color: #444; width: 200px; }
  • 11. The attribute selector can also be declared using just the attribute itself, with no value, like this: This will match all input elements with an attribute of type, regardless of the value. Attribute Selector… input[type] { background-color: #444; width: 200px; }
  • 12. A pseudo-class uses a colon character to identify a pseudo-state that an element might be in—for example, the state of being hovered, or the state of being activated. This means that when the user hovers their mouse over an element, the color property for that element will change to red. Pseudo-class a:hover { color: red; }
  • 13. Some of the most frequently used pseudo-classes are as follows: :first-child pseudo-class The :first-child pseudo-class matches an element that is the first child element of some other element. Pseudo-class… div > p:first-child { text-indent: 0 }
  • 14. The link pseudo-classes: :link and :visited • The :link pseudo-class applies for links that have not yet been visited. • The :visited pseudo-class applies once the link has been visited by the user. Pseudo-class… a:link { color: blue } a:visited { color: purple }
  • 15. The dynamic pseudo-classes: :hover, :active, and :focus • The :hover pseudo-class applies while the user designates an element (with some pointing device), but does not activate it. • The :active pseudo-class applies while an element is being activated by the user. • The :focus pseudo-class applies while an element has the focus (accepts keyboard events or other forms of text input). Pseudo-class…
  • 16. Pseudo-class… The last selector matches A elements that are in pseudo- class :focus and in pseudo-class :hover. a:link { color: red } /* unvisited links */ a:visited { color: blue } /* visited links */ a:hover { color: yellow } /* user hovers */ a:active { color: lime } /* active links */ a:focus { background: yellow } a:focus:hover { background: white }