SlideShare a Scribd company logo
1 of 39
Download to read offline
Introduction to
CSS selectors
@RichardCarter
Introduction to
CSS selectors
@RichardCarter
@RichardCarter
CSS selectors:
#FUCK>YEAH
@RichardCarter
Element selectors
div {
border: green;
}
p {
color: red
}
@RichardCarter
Descendant selectors
ul li {
border-bottom:
1px #ccc solid;
}
header ul li {
border-bottom:
1px #ccc solid;
}
header .lego {
border-bottom:
1px #ccc solid;
}
@RichardCarter
Classes and IDs
<img id=“lego”
src=“lego.jpg”
alt=“LEGO ftw” />
#lego {
display: block;
}
@RichardCarter
Better to use classes:
IDs have high specificity
train.jpg simpsons.jpg
<img class=“lego train”
src=“train.jpg”
alt=“LEGOTrains ftw” />
<img class=“lego simpsons”
src=“simpsons.jpg”
alt=“LEGO Simpsons ftw” />
.lego {
border: 1px red solid;
}
.simpsons {
border-color: #09C;
}
train.jpg simpsons.jpg
@RichardCarter
Live coding time!
(This is @libwella’s fault)
@RichardCarter
Chained selectors
.lego.simpsons {
border-color: blue;
}
@RichardCarter
Adjacency selector
h1 + p {
color: blue;
}
@RichardCarter
General sibling
selectors
p ~ p {
color: blue;
}
<p>LEGO</p>
<p>LEGO</p>
<div>LEGO</div>
<p>LEGO</p>
@RichardCarter
Child selector
// target only first-level li
ul>li {
font-weight: bold;
}
@RichardCarter
Attribute selectors
input[style] {
}
// exact match
input[type=“password”] {
}
// one exact match
input[class~=“lego”] {
}
// exact match, separated by -
p[lang|=“en”] {
}
// all class values starting
‘lego’
input[class^=“lego”] {
}
// all class values starting
‘lego’
input[class$=“lego”] {
}
// all class values ending
‘lego’
input[class*=“lego”] {
}
@RichardCarter
“There is always
someone better
than you”
~@sebly
Questions?
Feel free to email
hello@peacockcarter.co.uk
with any questions.
Had fun?
Learned something?
@RichardCarter
facebook.com/peacockcarter

More Related Content

What's hot

Completing Your Design with WordPress
Completing Your Design with WordPressCompleting Your Design with WordPress
Completing Your Design with WordPress
Chelsea Otakan
 
CSS Generator Tools
CSS Generator ToolsCSS Generator Tools
CSS Generator Tools
lillianabe
 

What's hot (20)

CSS 101
CSS 101CSS 101
CSS 101
 
Web 102 INtro to CSS
Web 102  INtro to CSSWeb 102  INtro to CSS
Web 102 INtro to CSS
 
Efficient, maintainable CSS
Efficient, maintainable CSSEfficient, maintainable CSS
Efficient, maintainable CSS
 
Intro to HTML + CSS
Intro to HTML + CSSIntro to HTML + CSS
Intro to HTML + CSS
 
presentation in html,css,javascript
presentation in html,css,javascriptpresentation in html,css,javascript
presentation in html,css,javascript
 
Css3
Css3Css3
Css3
 
Maintainable CSS
Maintainable CSSMaintainable CSS
Maintainable CSS
 
Css intro
Css introCss intro
Css intro
 
Completing Your Design with WordPress
Completing Your Design with WordPressCompleting Your Design with WordPress
Completing Your Design with WordPress
 
What's a web page made of?
What's a web page made of?What's a web page made of?
What's a web page made of?
 
Lab#7 CSS Box Model
Lab#7 CSS Box ModelLab#7 CSS Box Model
Lab#7 CSS Box Model
 
HTML & CSS
HTML & CSSHTML & CSS
HTML & CSS
 
CSS Generator Tools
CSS Generator ToolsCSS Generator Tools
CSS Generator Tools
 
Languages for web(HTML,CSS,JS)
Languages for web(HTML,CSS,JS)Languages for web(HTML,CSS,JS)
Languages for web(HTML,CSS,JS)
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
How to dominate a free theme WCTO 2014
How to dominate a free theme WCTO 2014How to dominate a free theme WCTO 2014
How to dominate a free theme WCTO 2014
 
3 Layers of the Web - Part 1
3 Layers of the Web - Part 13 Layers of the Web - Part 1
3 Layers of the Web - Part 1
 
Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...Introduction to web design discussing which languages is used for website des...
Introduction to web design discussing which languages is used for website des...
 
Web 101
Web 101Web 101
Web 101
 
HTML(5) and CSS(3) for beginners - I
HTML(5) and CSS(3) for beginners - IHTML(5) and CSS(3) for beginners - I
HTML(5) and CSS(3) for beginners - I
 

Viewers also liked

CSS: selectors and the box model
CSS: selectors and the box modelCSS: selectors and the box model
CSS: selectors and the box model
Idan Gazit
 
Face Recognition Technology
Face Recognition TechnologyFace Recognition Technology
Face Recognition Technology
Agrani Rastogi
 

Viewers also liked (17)

Color schemes
Color schemesColor schemes
Color schemes
 
Your CSS is Awesome
Your CSS is AwesomeYour CSS is Awesome
Your CSS is Awesome
 
Simplifying CSS Selectors
Simplifying CSS SelectorsSimplifying CSS Selectors
Simplifying CSS Selectors
 
What is Modular CSS?
What is Modular CSS?What is Modular CSS?
What is Modular CSS?
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
 
CSS: selectors and the box model
CSS: selectors and the box modelCSS: selectors and the box model
CSS: selectors and the box model
 
BEM it!
BEM it!BEM it!
BEM it!
 
CSS Selectors
CSS SelectorsCSS Selectors
CSS Selectors
 
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
Responsive Design Workflow (Breaking Development Conference 2012 Orlando)
 
Object Oriented CSS
Object Oriented CSSObject Oriented CSS
Object Oriented CSS
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
The benefits of BEM CSS
The benefits of BEM CSSThe benefits of BEM CSS
The benefits of BEM CSS
 
Face Recognition Technology
Face Recognition TechnologyFace Recognition Technology
Face Recognition Technology
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
FACE RECOGNITION TECHNOLOGY
FACE RECOGNITION TECHNOLOGYFACE RECOGNITION TECHNOLOGY
FACE RECOGNITION TECHNOLOGY
 
Atomic design
Atomic designAtomic design
Atomic design
 

Similar to CSS Selectors

Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
Felipe Lavín
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
Wynn Netherland
 
Webpages And Dynamic Content
Webpages And Dynamic ContentWebpages And Dynamic Content
Webpages And Dynamic Content
maycourse
 
Css sprite_maker-1
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1
lokku
 

Similar to CSS Selectors (20)

Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
 
Revolver
RevolverRevolver
Revolver
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for that
 
Beyond CSS Architecture
Beyond CSS ArchitectureBeyond CSS Architecture
Beyond CSS Architecture
 
The Creative New World of CSS
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSS
 
HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015
 
PreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 TricksPreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 Tricks
 
CSS::SpriteMaker in action!
CSS::SpriteMaker in action!CSS::SpriteMaker in action!
CSS::SpriteMaker in action!
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
 
Happy Browser, Happy User! NY Web Performance Meetup 9/20/19
Happy Browser, Happy User! NY Web Performance Meetup 9/20/19Happy Browser, Happy User! NY Web Performance Meetup 9/20/19
Happy Browser, Happy User! NY Web Performance Meetup 9/20/19
 
Cssxcountry slides
Cssxcountry slidesCssxcountry slides
Cssxcountry slides
 
Cssxcountry slides
Cssxcountry slidesCssxcountry slides
Cssxcountry slides
 
HTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.pptHTML Web Devlopment presentation css.ppt
HTML Web Devlopment presentation css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
css.ppt
css.pptcss.ppt
css.ppt
 
Webpages And Dynamic Content
Webpages And Dynamic ContentWebpages And Dynamic Content
Webpages And Dynamic Content
 
CSS and image optimization
CSS and image optimizationCSS and image optimization
CSS and image optimization
 
Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017
 
Getting Started With Angular
Getting Started With AngularGetting Started With Angular
Getting Started With Angular
 
Css sprite_maker-1
Css  sprite_maker-1Css  sprite_maker-1
Css sprite_maker-1
 

More from frontendne (8)

Reacting pragmatically
Reacting pragmaticallyReacting pragmatically
Reacting pragmatically
 
Improving your workflow with gulp
Improving your workflow with gulpImproving your workflow with gulp
Improving your workflow with gulp
 
An introduction in to the world of front end automation - frontend ne (02 07-15)
An introduction in to the world of front end automation - frontend ne (02 07-15)An introduction in to the world of front end automation - frontend ne (02 07-15)
An introduction in to the world of front end automation - frontend ne (02 07-15)
 
CSS Pseudo Classes
CSS Pseudo ClassesCSS Pseudo Classes
CSS Pseudo Classes
 
Marionette: the Backbone framework
Marionette: the Backbone frameworkMarionette: the Backbone framework
Marionette: the Backbone framework
 
Marionette: Building your first app
Marionette: Building your first appMarionette: Building your first app
Marionette: Building your first app
 
Css to-scss
Css to-scssCss to-scss
Css to-scss
 
Speedy, solid, semantic layout with Susy
Speedy, solid, semantic layout with SusySpeedy, solid, semantic layout with Susy
Speedy, solid, semantic layout with Susy
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

CSS Selectors