Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS3 Selectors - ConFoo 2014

Rachel Andrew
February 27, 2014

CSS3 Selectors - ConFoo 2014

My talk on CSS3 Selectors - with a bit of bonus info on the Level 4 Selectors Module.

Rachel Andrew

February 27, 2014
Tweet

More Decks by Rachel Andrew

Other Decks in Technology

Transcript

  1. • Working Draft • Candidate Recommendation • Proposed Recommendation •

    W3C Recommendation W3C Maturity Levels Thursday, 27 February 14
  2. h1 {} p {} .thing {} #uniquething {} .thing p

    Basic Selectors Thursday, 27 February 14
  3. target an element when it is the first child of

    a parent element :first-child Thursday, 27 February 14
  4. <div class=”wrapper”> <p> ... </p> <p> ... </p> <p> ...

    </p> </div> :first-child Thursday, 27 February 14
  5. target an element when it is the last child of

    a parent element :last-child Thursday, 27 February 14
  6. 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 Thursday, 27 February 14
  7. matches an element if it is the only child element

    of it’s parent. :only-child Thursday, 27 February 14
  8. p { padding: 0 0 1em 0; margin: 0; }

    p:empty { padding: 0; } :empty Thursday, 27 February 14
  9. matching virtual elements that don’t explicitly exist in the document

    tree Pseudo-elements Thursday, 27 February 14
  10. .clearfix:after { visibility: hidden; display: block; font-size: 0; content: "

    "; clear: both; height: 0; } .clearfix { display: inline-block; } /* start commented backslash hack \*/ * html .clearfix { height: 1%; } .clearfix { display: block; } /* close commented backslash hack */ Clear Fix Thursday, 27 February 14
  11. Select all elements that are descendants of a specified parent

    Descendant Selector Thursday, 27 February 14
  12. Select all elements that are immediate children of a specified

    parent Child Selector Thursday, 27 February 14
  13. <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 Thursday, 27 February 14
  14. li { color: #000; } ul > li { color:

    red; } Child Selector Thursday, 27 February 14
  15. Select elements that are the adjacent siblings of an element

    Adjacent Sibling Thursday, 27 February 14
  16. 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: first-child Thursday, 27 February 14
  17. 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> jQuery: nth-child Thursday, 27 February 14
  18. 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/ What is a polyfill? Thursday, 27 February 14
  19. Selectors Level 4 a look to the near future with

    “CSS4 Selectors” Thursday, 27 February 14
  20. :not Level 4 enables the passing of multiple selectors to

    :not p:not(.excerpt, .intro) { font-weight: normal; } Thursday, 27 February 14
  21. The local-link Pseudo-class Allows an author to style links depending

    on the visitor’s location in the site. For example to differentiate between local and external links. Thursday, 27 February 14
  22. :local-link(0) Links in the same domain - local links. a:local-link(0)

    { border-bottom: 1px dashed blue; } Thursday, 27 February 14
  23. Time Dimensional Pseudo-classes Defines :current :past and :future - useful

    to show progress through a document, for example when displaying subtitles. Thursday, 27 February 14
  24. Tree Structural Pseudo-classes Taking nth-child to the next level with

    :nth-match and :nth-last-match Thursday, 27 February 14
  25. Identifying the subject of the selector <ul> <li><a href=”home”>Home</a></li> <li><a

    class=”active”>About</a></ li> </ul> ul li a.active { color: blue; } ul li! a.active { border:1px solid blue; } Thursday, 27 February 14
  26. CSS Level 4 selectors Browsers are beginning to implement these

    selectors. See what your browser supports: http://css4-selectors.com/browser-selector-test/ Thursday, 27 February 14