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

A Tale of Four Properties

Chris Coyier
October 02, 2017

A Tale of Four Properties

This isn't nearly as fun without the video and music. So watch the actual presentation here:

Chris Coyier

October 02, 2017
Tweet

More Decks by Chris Coyier

Other Decks in Design

Transcript

  1. A Tale of Four
    Properties
    That are kinda related to shapes in CSS
    Chris Coyier @chriscoyier // CodePen • CSS-Tricks • ShopTalk

    View Slide

  2. `

    View Slide

  3. LET'S JUST SAY

    View Slide

  4. YOU REALLY LIKE
    REALLY

    View Slide

  5. THEY MIGHT
    BE GIANTS

    View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. YOU REALLY
    ONLY HAVE
    One Choice

    View Slide

  10. FAN SITE!!!!

    View Slide

  11. LYRICS
    ANDANDAND
    OMGSTUFFFFF
    What goes on a fan site?

    View Slide

  12. GUESTBOOK
    TMBG!!!!
    LYRICS!!!!
    PHOTOS!!!!
    CLUBHOUSE
    VISITOR COUNTER: 1113459784

    View Slide

  13. Let's make a SUPER FUN lyrics page for
    PARTICLE MAN

    View Slide


  14. Particle Man
    Particle man, particle man

    Doing the things a particle can

    What's he like? It's not important

    Particle man
    Is he a dot, or is he a speck?

    When he's underwater does he get wet?

    Or does the water get him instead?

    Nobody knows, Particle man
    Triangle man, Triangle man

    Triangle man hates particle man

    They have a fight, Triangle wins

    Triangle man
    Universe man, Universe man

    Size of the entire universe man

    Usually kind to smaller man

    Universe man

    View Slide


  15. Particle Man
    Particle man, particle man

    Doing the things a particle can

    What's he like? It's not important

    Particle man
    Is he a dot, or is he a speck?

    When he's underwater does he get wet?

    Or does the water get him instead?

    Nobody knows, Particle man
    Triangle man, Triangle man

    Triangle man hates particle man

    They have a fight, Triangle wins

    Triangle man
    Universe man, Universe man

    Size of the entire universe man

    Usually kind to smaller man

    Universe man

    View Slide

  16. I AM GONNA NEED THAT TEXT
    IDEA TIME
    TO BE ALL SLANTED UP.
    LIKE TRIANGLE MAN!!!!

    View Slide

  17. I AM GONNA NEED THA
    IDEA TIME
    TO BE ALL SLANTED
    LIKE TRIANGLE

    View Slide

  18. Particle Man

    Particle man, particle man
    Doing the things a particle can
    What's he like? It's not important
    Particle man
    Is he a dot, or is he a speck?
    When he's underwater does he get wet?
    Or does the water get him instead?
    Nobody knows, Particle man
    Triangle man, Triangle man
    Triangle man hates particle man
    They have a fight, Triangle wins
    Triangle man
    Universe man, Universe man
    Size of the entire universe man
    Usually kind to smaller man
    Universe man
    Hey it's got the
    right indie spirit!
    but we can do
    "better", I guess.

    View Slide

  19. View Slide

  20. ELEMENT
    THAT IS
    FLOATED

    View Slide

  21. There is a cool property that allows
    us to SHAPE that floated element.
    (In the future, we might be able to do this without having to float the element with CSS exclusions.)

    View Slide

  22. .shape {
    float: left;
    width: 200px;
    height: 200px;
    }
    ELEMENT
    THAT IS
    FLOATED

    View Slide

  23. ELEMENT
    THAT IS
    FLOATED
    .shape {
    float: left;
    width: 200px;
    height: 200px;
    shape-outside
    }

    View Slide

  24. ELEMENT
    THAT IS
    FLOATED
    .shape {
    float: left;
    width: 200px;
    height: 200px;
    shape-outside:
    polygon(
    );
    }

    View Slide

  25. ELEMENT
    THAT IS
    FLOATED
    .shape {
    float: left;
    width: 200px;
    height: 200px;
    shape-outside:
    polygon(
    100px 0,
    200px 200px,
    0 200px
    );
    }

    View Slide

  26. ELEMENT
    THAT IS
    FLOATED
    .shape {
    float: left;
    width: 200px;
    height: 200px;
    shape-outside:
    polygon(
    100px 0,
    200px 200px,
    0 200px
    );
    }

    View Slide

  27. shape-outside is like chipping away
    at a floated element.
    redefining

    View Slide

  28. View Slide

  29. You can even ANIMATE it.

    View Slide

  30. View Slide

  31. .shape {
    transition: shape-outside 2s ease-in-out;
    float: left;
    width: 99%;
    height: 100%;
    }
    .triangle-off {
    shape-outside: polygon(0 0, 0 100%, 0 100%, 0 0);
    }
    .triangle-man {
    shape-outside: polygon(0 0, 0 100%, 50% 100%, 0 0);
    }
    Basically a zero-width triangLE
    the real triangle

    View Slide

  32. https://codepen.io/netsi1964/pen/gLvyxj

    View Slide

  33. NOW LET'S DO
    UNIVERSE MAN

    View Slide

  34. UNIVERSE MAN
    HE's GONNA BUTT IN AND
    SMASH HIS BELLY ALL UP IN
    THIS TEXT!!!!

    View Slide

  35. https:/
    /www.youtube.com/watch?v=LsAiCs66l40

    View Slide

  36. shape-outside can take a
    circle() or ellipse() as well
    as polygon().

    View Slide

  37. .shape {
    transition: shape-outside 2s ease-in-out;
    float: left;
    width: 99%;
    height: 100%;
    }
    .universe-off {
    shape-outside: ellipse(200px 200px at 0 -300px);
    }
    .universe-man {
    shape-outside: ellipse(200px 200px at 0 300px);
    }
    Moved to nowheresville

    View Slide

  38. floated thing

    View Slide

  39. View Slide

  40. View Slide

  41. View Slide

  42. View Slide

  43. button.addEventListener("click", function() {
    // Immediately remove base class
    xman.classList.remove("triangle-man", "universe-man");
    clickedGuy = button.getAttribute("data-class");
    if (currentGuy === "") {
    xman.classList.add(clickedGuy);
    currentGuy = clickedGuy;
    } else {
    // Add the class for transitioning OFF
    xman.classList.add(currentGuy + "-off");
    xman.classList.remove(currentGuy);
    setTimeout(function() {
    xman.classList.remove(currentGuy + "-off");
    // Add the final ON class
    xman.classList.add(clickedGuy + "-off");
    setTimeout(function() {
    xman.classList.add(clickedGuy);
    currentGuy = clickedGuy;
    }, 100);
    }, 2000);
    }
    You can't transition
    a polygon() to an
    ellipse()
    This javascript is
    all about
    manipulating
    classes so
    transitions are
    always shape-to-
    shape

    View Slide

  44. There is actually tasteful
    stuff you can do with
    shape-outside()

    View Slide

  45. https://codepen.io/stacy/pen/aWKerN

    View Slide

  46. View Slide

  47. View Slide

  48. MAYBE
    PERSON MAN?

    View Slide

  49. View Slide

  50. polygon() circle() ellipse() inset() path() url()
    shape-outside
    ❌ #

    View Slide

  51. PERSON MAN?

    View Slide

  52. polygon() circle() ellipse() inset() path() url()
    shape-outside

    This is all assuming we're in a browser
    that supports shape-outside at all!

    View Slide

  53. You can kinda fake curves with
    polygons with lots of points...

    View Slide

  54. Let's just put a pin in that.

    View Slide

  55. WE NEED TO DEAL
    WITH PARTICLE
    MAN OMGG!!!!

    View Slide

  56. WITH PARTICLE
    MAN OMGG!!!!
    HE NEEDS TO BE FLYING ALL
    AROUND THIS SUCKAAAA LIKE
    A PARTICLE WOULD!!!!

    View Slide

  57. View Slide

  58. AIN't no polygon() gonna
    work here.
    I need fluid motion action!!!!

    View Slide

  59. Fortunately there is a perfect CSS
    property for us: offset-path()

    View Slide

  60. Actually, it used to be called motion-path()

    View Slide

  61. .thing-that-moves {
    /* "Old" syntax.
    Available in Blink browsers as of ~October 2015 */
    motion-path: ;
    /* Currently spec'd syntax.
    Should be in stable Chrome as of ~December 2016 */
    offset-path: ;
    }

    View Slide

  62. .thing-that-moves {
    /* "Old" syntax.
    Available in Blink browsers as of ~October 2015 */
    motion-path: path("M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8
    /* Currently spec'd syntax.
    Should be in stable Chrome as of ~December 2016 */
    offset-path: path("M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8
    }

    View Slide

  63. PATHS ARE
    AWESOME
    they can draw anything!!!!
    All other drawing is syntactic sugar!!!!

    View Slide

  64. Path comes from SVG land.

    View Slide

  65. https://css-tricks.com/svg-path-syntax-illustrated-guide/

    View Slide

  66. View Slide

  67. View Slide

  68. View Slide


  69. #particle-man {
    width: 5px;
    height: 5px;
    background: blue;
    offset-path: path('m68.5,161c0,0 53,-121 152,-66c99,55 146,241
    293,99c147,-142 -54,-163 -126.5,-126c-72.5,37 -92.5,369
    -229.5,249c-137,-120 55,-222 145,-193c90,29 6,284 104,222c98,-62 240,-319
    -75,-268c-315,51 167,336 -91,292c-258,-44 -172,-209 -172,-209z');
    animation: is-he-a-dot-or-is-he-a-spec 3s linear infinite;
    }
    @keyframes is-he-a-dot-or-is-he-a-spec {
    100% { motion-offset: 100%; } /* defaults to 0 */
    }
    HTML
    CSS

    View Slide

  70. View Slide

  71. View Slide

  72. View Slide

  73. Here's the rub:
    offset-path only takes path()

    View Slide

  74. A litttttttle bit WHAT THE F*CK.
    A litttttttle bit understandable.

    View Slide

  75. It is called offset-path...
    But more importantly, paths have a
    direction. circle() is a nice syntax for a
    circle, but it doesn't tell you what direction
    to travel along it all by itself. A path does.

    View Slide

  76. polygon() circle() ellipse() inset() path() url()
    shape-outside


    offset-path ❌ ❌ ❌ ❌

    View Slide

  77. There is actually tasteful,
    nice stuff you can do with
    offset-path()

    View Slide

  78. View Slide

  79. View Slide

  80. View Slide

  81. WE GONNA NEED SOME
    SURPRISING REVEALS!
    IDEA TIME

    View Slide

  82. LET's make a lyrics page
    for your racist friend!!!!

    View Slide

  83. View Slide

  84. View Slide

  85. You can clip elements!
    With clip-path!

    View Slide

  86. Remember how with
    shape-outside we could use shapes
    like polygon() and circle()?
    Those work with clip-path too!
    The old name was clip.

    View Slide

  87. Here's another one: inset()

    View Slide

  88. clip-path:
    inset(
    0 /* top */
    20px /* right */
    20px /* bottom */
    280px /* left */
    );

    View Slide

  89. .racist-friend {
    position: fixed;
    bottom: -4px;
    left: 0;
    display: block;
    width: 500px;
    transition: 1.5s;
    transform: translateX(-200px);
    clip-path: inset(0 20px 20px 280px);
    &:hover {
    transform: translateX(0);
    clip-path: inset(0 0 0 0);
    }
    }

    View Slide

  90. View Slide

  91. There is actually tasteful,
    nice stuff you can do with
    clip-path()

    View Slide

  92. View Slide

  93. clip-path: polygon(
    0 0, 100% 4%, 100% 93%, 0 100%
    );
    clip-path: polygon(
    0 0, 100% 6%, 100% 100%, 0 94%
    );
    https://codepen.io/chriscoyier/pen/EVQweM?editors=1100

    View Slide

  94. div {
    clip-path: polygon(100%
    0%, 75% 50%, 100% 100%,
    25% 100%, 0% 50%, 25% 0%);
    animation: shimmy 1s
    infinite alternate ease-
    in-out;
    }
    @keyframes shimmy {
    100% {
    clip-path: polygon(75%
    0%, 100% 50%, 75% 100%, 0%
    100%, 25% 50%, 0% 0%);
    }
    }
    https://codepen.io/chriscoyier/pen/EyjvgV

    View Slide

  95. https://codepen.io/chriscoyier/pen/wBKPOm/

    View Slide

  96. div {
    transition: 0.4s cubic-bezier(1, -1, 0, 2);
    clip-path: polygon(50% 5%, 0% 100%, 100% 100%);
    }
    div:hover {
    clip-path: polygon(50% 19%, 0 76%, 100% 76%);
    }

    View Slide

  97. https://codepen.io/noeldelgado/pen/PZJGLx?ed

    View Slide

  98. https://codepen.io/suez/pen/grJONP

    View Slide

  99. View Slide

  100. Guess what?
    It's sad.
    No path()

    View Slide

  101. polygon() circle() ellipse() inset() path() url()
    shape-outside

    offset-path
    ❌ ❌ ❌ ❌ ❌
    clip-path





    View Slide

  102. There are ways to get curved clipping:
    1) Use clip-path: url("#clipPath");
    2) Use mask which can point to an SVG file,
    which can have paths.)

    View Slide

  103. View Slide

  104. View Slide

  105. SO. SPEAKING
    OF SVG.

    View Slide

  106. SO. SPEAKING
    OF SVG.

    View Slide

  107. SO. SPEAKING
    OF SVG.

    View Slide

  108. SVG doesn't have wrapped text or floats, so
    shape-outside isn't really relevant.
    SVG has clipping and masking covered with
    and .
    SVG has for animating
    along a path. But it's part of SMIL.

    View Slide

  109. My suspicion of why we've gotten so
    much of this stuff in CSS recently is:
    1) The popularity of SVG recently.
    2) The proposed deprecation of SMIL.

    View Slide

  110. View Slide

  111. View Slide

  112. View Slide

  113. WHERE WAS I

    View Slide



  114. d="M 200 200 v 20 h -20" />
    path {
    /* Yes */ d: path("M 200 200 v 20 h -20");
    }
    polygon {
    /* No */ points: polygon("0,0 30,0 20,20 0,20");
    /* No */ points: "0,0 30,0 20,20 0,20";
    }
    circle {
    /* Yes */ cx: 40;
    /* Yes */ cy: 40;
    /* Yes */ r: 20;
    }
    ellipse {
    /* Yes */ rx: 10;
    /* Yes */ ry: 10;
    }
    rect {
    /* Yes */ x: 10;
    /* Yes */ y: 100;
    /* Yes */ width: 300px; /* Weird */
    /* Yes */ height: 20px; /* Weird */
    }
    points="0,0 20,0 20,20 0,20" />
    cx="50" cy="50" r="10" />
    cx="60" cy="60" rx="50" ry="25" />
    x="120" y="120" width="12" height="12" />

    View Slide

  115. polygon() circle() ellipse() inset() path() url()
    shape-outside

    offset-path ❌ ❌ ❌ ❌

    clip-path

    d ~ ~ ~ ~ ~

    View Slide

  116. GOSH IT
    WOULD BE NICE

    View Slide

  117. If shape-outside could use path()
    If shape-outside could use url(#fragment)
    To know if path() going to stay like it is.
    To know what's up with unitless/lengths.
    If could use polygon()
    WOULD BE NICE

    View Slide

  118. BUT
    ANYWAY

    View Slide

  119. Word on the street is the CSS folks
    have a desire to reign all this in.

    View Slide

  120. They all tend to work
    fairly well with
    P
    r
    o
    g
    r
    e
    s
    s
    I
    v
    eNHANCEMENT

    View Slide

  121. There is a ton of cool stuff we can
    do with all these properties and
    values now.

    View Slide

  122. View Slide

  123. THANKS
    Chris Coyier @chriscoyier // CodePen • CSS-Tricks • ShopTalk

    View Slide