SlideShare una empresa de Scribd logo
1 de 106
Descargar para leer sin conexión
CSS3 &
SELECTORS
RACHEL ANDREW

   @rachelandrew
  rachelandrew.co.uk
  edgeofmyseat.com
    grabaperch.com
WHAT IS
CSS3?
CSS3 IS THE
NEXT VERSION
  OF CSS
CSS3 IS
MODULAR
SOME CSS3 MODULES
ARE MORE COMPLETE
   THAN OTHERS
W3C MATURITY LEVELS
Working Draft
Candidate Recommendation
Proposed Recommendation
W3C Recommendation
http://www.w3.org/2005/10/Process-20051014/tr#maturity-levels
CSS3 IS SUPPORTED BY
          BROWSERS

Some browsers and some (parts of) modules.
USING CSS3
SELECTORS MODULE

   W3C Proposed Recommendation
http://www.w3.org/TR/css3-selectors/
BASIC SELECTORS
h1 {}

p {}

.thing {}

#uniquething {}

.thing p
THE PROBLEM
 WITH CSS2
 SELECTORS
ADDING CLASSES


<h1>My heading</h1>
<p class=”first”> ... </p>
<p> ... </p>
CSS3 SELECTORS
        “Common sense” new selectors
target elements more precisely without adding
                  classes
STRUCTURAL PSEUDO-
 CLASS SELECTORS
PSEUDO-CLASS
       SELECTORS
a:link {}
a:visited {}
DYNAMIC
     PSEUDO-CLASS
a:hover {}
a:active {}
:first-child

target an element when it is the first child of a
               parent element
:first-child
:first-child

div#wrapper p {
! ! font-size: 1.5em;
}
:first-child

div#wrapper p:first-child {
! ! font-size: 1.5em;
}
:first-child
:last-child

target an element when it is the last child of a
              parent element
:last-child
:last-child

ul#navigation li:last-child {
! ! border-bottom: none;
}
:last-child
:nth-child

select multiple elements according to their
       position in the document tree
:nth-child
:nth-child

tr:nth-child(odd) td {
! ! background-color: #f0e9c5;
}
:nth-child
:nth-child

tr:nth-child(3) td {
! ! background-color: #f0e9c5;
}
:nth-child
:nth-child

tr:nth-child(2n+1) td {
! ! background-color: #f0e9c5;
}


   http://reference.sitepoint.com/css/understandingnthchildexpressions
:nth-of-type

   select multiple elements according to their
  position in the document tree BUT only those
elements that are the same as the type the rule is
                    applied to.
:nth-of-type

p:nth-of-type(odd) {
! ! background-color: #f0e9c5;
}
:nth-of-type
:only-child

matches an element if it is the only child element
                of it’s parent.
:only-child
li {
! list-style-type: disc;
}
!
li:only-child {
! list-style-type: none;
}
:only-child
:empty

matches an element if it is empty
:empty
p {
! padding: 0 0 1em 0;
! margin: 0;
}
!
p:empty {
! padding: 0;
}
FOR INPUT ELEMENTS

Structural pseudo-classes for use with forms.
:checked

the checked state of a checkbox or radio button
:checked

#agreeterms:checked {
  border:2px solid blue;
}
ENABLED AND DISABLED

   detecting input element states
:enabled

input:enabled {
  color: #000;
}
:disabled

input:disabled {
  color: #999;
}
THE NEGATION PSEUDO-
       CLASS

       :not(selector)
:not
<p> ... </p>
<p class=”box”> ... </p>
<p> ... </p>
:not
p:not(.box) {
! padding: 0 0 3em 0;
! margin: 0;
}
!
p.box {
! border:1px solid #000;
! margin: 0 0 2em 0;
}
:not
PSEUDO-ELEMENTS
:first-letter

the first character of the first line of text
:first-letter
div#wrapper:first-letter {
! font-size: 200%;
! font-weight: bold;
! color: red;
}
:first-letter
:first-line

the first formatted line of text
:first-line
div#wrapper:first-line {
! font-size: 200%;
! font-weight: bold;
! color: red;
}
:first-line
:before

Render content before the element when using
             generated content
:before

<div id=”content”> ... </div>
:before
#content:before {
  content: "Start here:";
}
:before
:after

Render content after the element when using
            generated content
:after
#content:after {
  content: "End here:";
}
::selection

Content selected in browser by the user
::selection
div#wrapper p::selection {!
  background-color: red;
}
::selection
COMBINATORS

Combining selectors to target elements
DESCENDANT SELECTOR

Select all elements that are descendants of a
               specified parent
DESCENDANT SELECTOR

div#wrapper p {
! font-size: 1.5em;
}
CHILD SELECTOR

Select all elements that are immediate children of
                a specified parent
CHILD SELECTOR
<ul>
 <li>Item 1
  <ol>
     <li>Sub list item 1</li>
     <li>Sub list item 2</li>
  </ol>
 </li>
 <li>Item 2</li>
</ul>
CHILD SELECTOR

li {
! color: #000;
}
!
ul > li {
! color: red;
}
Child Selector
ADJACENT SIBLING

Select elements that are the adjacent siblings of
                 an element
ADJACENT SIBLING

div#wrapper h1 + p {
! font-size: 1.5em;
}
Adjacent Sibling
GENERAL SIBLING

Select elements that are the siblings of an
                element
GENERAL SIBLING

div#wrapper h2~p {
! color: red;
}
General Sibling
ATTRIBUTE SELECTORS

  Select elements based on attributes
ATTRIBUTE SELECTORS

form input[type="text"] {

}
!
form input[type="submit"] {

}
Attribute Selectors
ATTRIBUTE SELECTORS

label[for="fContact"] {
    ! float: none;
    ! width: auto;
}
ATTRIBUTE SELECTORS

a[href ^="mailto:"] {
! ! padding-right: 20px;
! ! background-image:url(email.png);
! ! background-repeat: no-repeat;
! ! background-position: right center;
}
BROWSER
SUPPORT
Browser Support
DOES IT
MATTER?
YES, IT
MATTERS.
JAVASCRIPT

Plug the holes in browser support using JavaScript.
JQUERY: FIRST-CHILD
div#wrapper p:first-child,
div#wrapper p.first {
! ! font-size: 1.5em;
}




<script src="http://code.jquery.com/jquery-latest.js"></
script>
<script>
  $(document).ready(function(){
! $("div#wrapper p:first-child").addClass("first");
  });
</script>
JQUERY: LAST-CHILD
ul#navigation li:last-child, ul#navigation li.last {
! ! border-bottom: none;
}




<script src="http://code.jquery.com/jquery-latest.js"></
script>
<script>
  $(document).ready(function(){
! $("ul#navigation li:last-child").addClass("last");
  });
</script>
JQUERY: NTH-CHILD
tr:nth-child(odd) td, td.odd {
! background-color: #f0e9c5;
}




<script src="http://code.jquery.com/jquery-latest.js"></
script>
<script>
  $(document).ready(function(){
! $("tr:nth-child(odd) td").addClass("odd");
  });
</script>
CSS “POLYFILLS”

 plugging the holes in support
WHAT IS A POLYFILL?
   A polyfill, or polyfiller, is a piece of code (or
plugin) that provides the technology that you, the
developer, expect the browser to provide natively.
      http://remysharp.com/2010/10/08/what-is-a-polyfill/
SELECTIVIZR

http://selectivizr.com/
ECSSTENDER

http://ecsstender.org/
CSS3 WORKFLOW

 How I approach my projects.
CSS3 WORKFLOW

Develop without any polyfill or JavaScript fixes in
                    place.
CSS3 WORKFLOW

     Validate.
CSS3 WORKFLOW

 Test & Fix in older browsers
CSS3 WORKFLOW

Decide if you need to use a polyfill and which kind
CSS3 WORKFLOW

    Test again.
THANK YOU!

  @rachelandrew
 rachelandrew.co.uk
 edgeofmyseat.com
   grabaperch.com

Más contenido relacionado

La actualidad más candente

Front End Good Practices
Front End Good PracticesFront End Good Practices
Front End Good Practices
Hernan Mammana
 
Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
SANTOSH RATH
 

La actualidad más candente (20)

Front End Good Practices
Front End Good PracticesFront End Good Practices
Front End Good Practices
 
HTML, CSS And JAVASCRIPT!
HTML, CSS And JAVASCRIPT!HTML, CSS And JAVASCRIPT!
HTML, CSS And JAVASCRIPT!
 
A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java script
 
Getting Started with DOM
Getting Started with DOMGetting Started with DOM
Getting Started with DOM
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Javascript
JavascriptJavascript
Javascript
 
CSS CASCADE
CSS CASCADECSS CASCADE
CSS CASCADE
 
Semantic markup - Creating Outline
Semantic markup -  Creating OutlineSemantic markup -  Creating Outline
Semantic markup - Creating Outline
 
Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
 
Week 2-intro-html
Week 2-intro-htmlWeek 2-intro-html
Week 2-intro-html
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
Web Typography
Web TypographyWeb Typography
Web Typography
 
Java script
Java scriptJava script
Java script
 
Css.html
Css.htmlCss.html
Css.html
 

Similar a CSS3 and Selectors

Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
guest5d87aa6
 

Similar a CSS3 and Selectors (20)

Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3
 
Html5 & CSS overview
Html5 & CSS overviewHtml5 & CSS overview
Html5 & CSS overview
 
CSS for Developers
CSS for DevelopersCSS for Developers
CSS for Developers
 
Oocss & progressive css3 selectors
Oocss & progressive css3 selectorsOocss & progressive css3 selectors
Oocss & progressive css3 selectors
 
CSS selectors
CSS selectorsCSS selectors
CSS selectors
 
CSS
CSSCSS
CSS
 
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)
 
Exam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NETExam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NET
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
Core CSS3
Core CSS3Core CSS3
Core CSS3
 
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
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
Css selectors
Css selectorsCss selectors
Css selectors
 
CSS- Smacss Design Rule
CSS- Smacss Design RuleCSS- Smacss Design Rule
CSS- Smacss Design Rule
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
Css Selectors
Css SelectorsCss Selectors
Css Selectors
 
9- Learn CSS Fundamentals / Pseudo-classes
9- Learn CSS Fundamentals / Pseudo-classes9- Learn CSS Fundamentals / Pseudo-classes
9- Learn CSS Fundamentals / Pseudo-classes
 
CSS Psuedo and beyond
CSS Psuedo and beyondCSS Psuedo and beyond
CSS Psuedo and beyond
 
Css advanced – session 5
Css advanced – session 5Css advanced – session 5
Css advanced – session 5
 
CSS3 and jQuery
CSS3 and jQueryCSS3 and jQuery
CSS3 and jQuery
 

Más de Rachel Andrew

Más de Rachel Andrew (20)

All Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutAll Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid Layout
 
SmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutSmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid Layout
 
Unlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid Layout
 
The Creative New World of CSS
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSS
 
Into the Weeds of CSS Layout
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS Layout
 
Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17
 
Graduating to Grid
Graduating to GridGraduating to Grid
Graduating to Grid
 
View Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & FriendsView Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & Friends
 
DevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout today
 
Start Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJS
 
404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends
 
Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17
 
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgLaying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf Freiburg
 
Solving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJS
 
Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout
 
Web Summer Camp Keynote
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp Keynote
 
New CSS Layout Meets the Real World
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real World
 
An Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real WorldAn Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real World
 
Perch, Patterns and Old Browsers
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old Browsers
 
Evergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsers
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
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
 
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?
 
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
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

CSS3 and Selectors