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

ConFoo: CSS3 Selectors

Rachel Andrew
February 28, 2013

ConFoo: CSS3 Selectors

Rachel Andrew

February 28, 2013
Tweet

More Decks by Rachel Andrew

Other Decks in Technology

Transcript

  1. CSS3 is supported by browsers Some browsers and some (parts

    of) modules. Thursday, 28 February 13
  2. h1 {} p {} .thing {} #uniquething {} .thing p

    Basic Selectors Thursday, 28 February 13
  3. a[href ^="mailto:"] { padding-right: 20px; ! background-image:url(email.png); ! background-repeat: no-repeat;

    ! background-position: right center; } Attribute Selectors Thursday, 28 February 13
  4. :first-child target an element when it is the first child

    of a parent element Thursday, 28 February 13
  5. <div class=”wrapper”> <p> ... </p> <p> ... </p> <p> ...

    </p> </div> :first-child Thursday, 28 February 13
  6. :last-child target an element when it is the last child

    of a parent element Thursday, 28 February 13
  7. :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. Thursday, 28 February 13
  8. :only-child matches an element if it is the only child

    element of it’s parent. Thursday, 28 February 13
  9. li { ! list-style-type: disc; } ! li:only-child { !

    list-style-type: none; } :only-child Thursday, 28 February 13
  10. p { ! padding: 0 0 1em 0; ! margin:

    0; } ! p:empty { ! padding: 0; } :empty Thursday, 28 February 13
  11. <input type="text" name="fName" id="fName" required="required" /> ! ! <input type="email"

    name="fEmail" id="fEmail" required="required" placeholder="[email protected]" /> HTML5 attributes Thursday, 28 February 13
  12. p:not(.box) { ! ! padding: 1em; ! ! border:2px solid

    #000; ! } :not Thursday, 28 February 13
  13. .wrapper:first-letter { ! font-size: 200%; ! font-weight: bold; ! color:

    red; } :first-letter Thursday, 28 February 13
  14. .wrapper:first-line { ! font-size: 200%; ! font-weight: bold; ! color:

    red; } :first-line Thursday, 28 February 13
  15. .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, 28 February 13
  16. Descendant Selector Select all elements that are descendants of a

    specified parent Thursday, 28 February 13
  17. Child Selector Select all elements that are immediate children of

    a specified parent Thursday, 28 February 13
  18. <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, 28 February 13
  19. li { ! color: #000; } ! ul > li

    { ! color: red; } Child Selector Thursday, 28 February 13
  20. .wrapper h1 + p { ! font-size: 1.5em; } Adjacent

    Sibling Thursday, 28 February 13
  21. div#wrapper p:first-child, div#wrapper p.first { ! ! font-size: 1.5em; }

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

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

    <script src="http://code.jquery.com/jquery-latest.js"></ script> <script> $(document).ready(function(){ ! $("tr:nth-child(odd) td").addClass("odd"); }); </script> Thursday, 28 February 13
  24. 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/ Thursday, 28 February 13
  25. var patch_css = function() { ! ! // supporting css

    stuff ! ! ! ! $('input[type=submit]').addClass('submit'); ! ! $('h1+h2').addClass('stacked'); ! ! $('h1+p').addClass('stacked'); ! ! ! }; patch_css Thursday, 28 February 13
  26. CSS3 Workflow Decide if you need to use a polyfill

    and which kind Thursday, 28 February 13