The ABCs of CSS You've Likely Never Used

The ABCs of CSS You've Likely Never Used

That Conference 2017

A5af583190a73a7d94255c6f79cde415?s=128

Alicia Sedlock

August 08, 2017
Tweet

Transcript

  1. 1.

    The ABCs of CSS Properties You’ve Likely Never Used (Well,

    Mostly!) Alicia Sedlock | @aliciability
  2. 2.

    Hi!

  3. 3.
  4. 5.
  5. 7.

    A additive-symbols “… specify symbols when the value of a

    counter system descriptor is additive.”
  6. 11.
  7. 12.

    dialog { /* some dialog styles */ } dialog::backdrop {


    
 background: black;
 opacity: .5;
 
 }
  8. 13.
  9. 16.
  10. 17.

    D :default
 
 “…represents any user interface element that is

    the default among a group of similar elements.”
  11. 18.

    :default { background-color: pink; } <form> <input type=“button” value=“Button” />

    <input type=“submit” /> <input type=“reset” /> </form>
  12. 19.
  13. 21.

    div {
 
 background: lightblue;
 
 } div:empty {
 


    background: pink;
 
 } <div><!— No content —></div> <div>Hello world!</div> <div>
 <!— No content —>
 </div>
  14. 22.
  15. 23.

    F ::first-letter
 
 “…applies styles to the first letter of

    the first line of a block-level element…”
  16. 25.

    p::first-letter {
 
 color: red;
 font-size: 3em;
 font-weight: bold;
 


    }
 
 <p>
 <img src=“fox.jpg” />
 The quick brown fox
 </p>
  17. 32.

    I :in-range
 
 “…matches when the value currently contained inside

    an <input> element is inside the range limits specified by the min and max attributes.”
  18. 33.
  19. 34.

    <label>Enter a number 1-10</label>
 <input type="number" min="1" max="10" value="12" />


    
 input:in-range {
 background-color: rgba(0, 255, 0, 0.25);
 }
 
 input:out-of-range {
 background-color: rgba(255, 0, 0, 0.25);
 border: 2px solid red;
 }
  20. 35.
  21. 36.

    J justify-content
 ONLY ENTRY
 
 “…defines how the browser distributes

    space between and around content items along the main axis of their container.”
  22. 37.

    .container {
 display: flex;
 justify-content: <value>;
 } <div class=“container”>
 <div><!—

    Content! —></div>
 <div><!— Content! —></div>
 <div><!— Content! —></div>
 </div>
  23. 38.

    .container {
 display: flex;
 justify-content: flex-start;
 } <div class=“container”>
 <div><!—

    Content! —></div>
 <div><!— Content! —></div>
 <div><!— Content! —></div>
 </div>
  24. 39.

    .container {
 display: flex;
 justify-content: flex-end;
 } <div class=“container”>
 <div><!—

    Content! —></div>
 <div><!— Content! —></div>
 <div><!— Content! —></div>
 </div>
  25. 40.

    .container {
 display: flex;
 justify-content: center;
 } <div class=“container”>
 <div><!—

    Content! —></div>
 <div><!— Content! —></div>
 <div><!— Content! —></div>
 </div>
  26. 41.

    .container {
 display: flex;
 justify-content: space-around;
 } <div class=“container”>
 <div><!—

    Content! —></div>
 <div><!— Content! —></div>
 <div><!— Content! —></div>
 </div>
  27. 42.

    .container {
 display: flex;
 justify-content: space-between;
 } <div class=“container”>
 <div><!—

    Content! —></div>
 <div><!— Content! —></div>
 <div><!— Content! —></div>
 </div>
  28. 48.

    
 :lang(en) { border: 1px solid red; } :lang(fr) {

    border: 1px solid blue; } :lang(de) { border: 1px solid black; }
  29. 49.

    M max-zoom
 
 “…sets the maximum zoom factor of a

    document defined by the @viewport at- rule."
  30. 51.

    N negative
 
 “…alters the representation of negative counter values,

    by providing a way to specify symbols to be appended or prepended to the counter representation when the value is negative.”
  31. 53.

    @counter-style negative-counter { system: numeric;
 symbols: "0" "1" "2" "3"

    "4" "5" "6" "7" "8" "9";
 negative: "(-" ")"; } .list { list-style: negative-counter; }
  32. 54.
  33. 55.

    O object-fit
 
 “…how a replaced element, such as an

    <img> or <video>, should be resized to fit its container.”
  34. 56.

    /* Base styles for examples */
 img { width: 400px;

    height: 500px; border: 5px solid pink; object-fit: <value>; }
  35. 57.
  36. 58.
  37. 59.
  38. 60.
  39. 61.
  40. 64.

    <div> Lorem ipsum dolor sit amet… </div> <div class="overlay"> I

    am an overlay. Try selecting the text behind me. </div>
  41. 65.

    .overlay { position: absolute; top: 0; left: 40%; background: rgba(0,0,0,.75);

    height: 200px; width: 250px; color: white; padding: 1em; pointer-events: auto; }
  42. 70.

    <span>According to Groot, <q>I am Groot.</q>.</span> 
 q { quotes:

    "**" “**”; } q:before { content: open-quote; } q:after { content: close-quote; }
  43. 71.

    <span>Peter Quill says <q>I'm pretty sure the answer is <q>I

    am Groot</q>.</q></span> 
 q { quotes: ’””’ ‘“”’ “‘’” “‘’”; } q:before { content: open-quote; } q:after { content: close-quote; }
  44. 72.

    R revert
 
 “…rolls back the cascade so that a

    property takes on the value it would have had if there were no styles in the current style origin"
  45. 73.
  46. 76.

    @counter-style counter-options { system: fixed;
 symbols: A B C D

    E F G;
 suffix: “) ”; } .list { list-style: counter-options; }
  47. 77.
  48. 79.

    pre { tab-size: 4; /* integer values */
 tab-size: 2;


    tab-size: 10px; /* length values */
 tab-size: 2em; }
  49. 80.

    <pre class=“default"> &#9;This is a line in pre! &#9;CSS is

    a lot of fun. :) </pre> pre { border: 1px solid black;
 width: 500px; }
  50. 81.

    <pre class=“default"> &#9;This is a line in pre! &#9;CSS is

    a lot of fun. :) </pre> pre { border: 1px solid black;
 width: 500px;
 tab-size: 4; }
  51. 82.

    <pre class=“default"> &#9;This is a line in pre! &#9;CSS is

    a lot of fun. :) </pre> pre { border: 1px solid black;
 width: 500px;
 tab-size: 100px; }
  52. 83.

    U unset
 
 “…resets a property to its inherited value

    if it inherits from its parent, and to its initial value if not.”
  53. 84.

    <p>I want to be blue text!</p> <div class="foo"> <p>I want

    to be orange text :(</p> </div> <div class="bar"> <p>I don't want to be orange.</p> </div> .foo { color: orange; } .bar { color: green; } p { color: blue; } .bar p { color: unset; }
  54. 85.
  55. 86.

    V vw/vh “Equal to 1% of the width/height of the

    viewport's initial containing block.”
  56. 87.

    W will-change “…provides a way for authors to hint browsers

    about the kind of changes to be expected on an element, so that the browser can set up appropriate optimizations ahead of time…”
  57. 88.
  58. 89.

    A warning on will-change • Intended as a “last resort”

    - don’t prematurely optimize • Meant to be used sparingly
  59. 90.
  60. 96.

    Some of these things are • Experimental technology • In

    working draft • In initial definition
  61. 99.
  62. 100.
  63. 102.
  64. 103.