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

CSS Grid Cards

Manz
July 19, 2018

CSS Grid Cards

Flexbox, Grid CSS, Position, Tranforms and others.

Manz

July 19, 2018
Tweet

More Decks by Manz

Other Decks in Programming

Transcript

  1. ♥ ♠ ♦ ♣ :spades: U+2660 U+FE0F :hearts: U+2665 U+FE0F

    :diamonds: U+2666 U+FE0F :clubs: U+2663 U+FE0F 4 suits / 4 emojis
  2. .deck for s in ['♠','♥','♦','♣'] for c in [1,2,3,4,5,6,7,8,9,10] .card(data-card=`${c}`,

    data-suit=`${s}`) for i in [...Array(c).keys()] span.item= s 10 ca s un aj (de ) 4 pa en ca , c e núme de ím o s re n e t ♠ ♠♠ ♠♠♠ ♠♠♠♠ ♠♠♠♠♠ ♠♠♠♠♠♠ ♠♠♠♠♠♠♠ ♠♠♠♠♠♠♠♠ ♠♠♠♠♠♠♠♠♠ ♠♠♠♠♠♠♠♠♠♠
  3. [data-card="4"] { display: grid; grid-template-rows: 50% 50%; grid-template-columns: 50% 50%;

    justify-items: center; align-items: center; } ♠ te l -co n te l -ro ♠ ♠ ♠ 50% 50% 50% 50%
  4. [data-card="5"] { display: grid; grid-template-areas: "a . b" ". c

    ." "d . e"; justify-items: center; align-items: center; & .item:nth-child(1) { grid-area: a; } ... } ♠ áre áre ♠ ♠ ♠ @use postcss-nested; áre áre ♠ áre Hay om r la 5 áre
  5. [data-card="6"], [data-card="7"], [data-card="8"] { display: grid; grid-template-rows: repeat(3,1fr); grid-template-columns: repeat(2,1fr);

    justify-items: center; align-items: center; } ♠ ♠ ♠ ♠ 1f 1f 1f ♠ ♠ 1f 1f 1f 1f 1f 2f 3f
  6. [data-card="7"], [data-card="8"] { position: relative; & .item:nth-child(1) { position: absolute;

    top: 20%; } } ♠ ♠ ♠ ♠ ♠ ♠♠ ♠ re ve ab te to 20%
  7. [data-card="9"], [data-card="10"] { display: grid; grid-template-rows: repeat(4, 25%); grid-template-columns: 50%

    50%; justify-items: center; align-items: center; position: relative; & .item:nth-child(1) { position: absolute; } } ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠♠ 50% 50% 25% 25% 25% 25% ab te
  8. [data-card="10"] { position: relative; & .item:nth-child(1) { position: absolute; top:

    15%; } & .item:nth-child(10) { position: absolute; bottom: 15%; } } ♠ ♠ ♠ ♠ ♠ ♠ ♠ ♠♠ ♠ bo m ♠ to
  9. [data-card="2"] .item:nth-child(n+2), [data-card="3"] .item:nth-child(n+3), [data-card="4"] .item:nth-child(n+3), [data-card="5"] .item:nth-child(n+4), [data-card="6"] .item:nth-child(n+5),

    [data-card="7"] .item:nth-child(n+6), [data-card="8"] .item:nth-child(n+6), [data-card="9"] .item:nth-child(n+6), [data-card="10"] .item:nth-child(n+6) { transform: translateY(8px) scaleY(-1); } s a Y -1 ♠ ♠
  10. ... for c in [1,2,3,4,5,6,7,8,9,10] ... for c in ['J','Q','K']

    .card(data-card=`${c}`, data-suit=`${s}`) span.item= c+s Jac , Qu n & Kin la ra + el J♠ Q♠ K♠
  11. [data-card="J"], [data-card="Q"], [data-card="K"] { display: flex; justify-content: center; align-items: center;

    & .item { border: 1px solid #ccc; border-radius: 10px; padding: 30px 12px; } } J♠ al -it ju f -co n
  12. [data-card] { position: relative; &::before { content: 'Manz'; font-size: 17px;

    position: absolute; } } c co n ne d re ve ♠ ♠ Manz
  13. [data-card] { position: relative; &::before, &::after { content: 'Manz'; font-size:

    17px; position: absolute; } &::before { top: 0; left: 0; } } ::af ::be ♠ Manz Manz es a s i r-iz am ♠
  14. [data-card] { position: relative; &::before, &::after { content: 'Manz'; font-size:

    17px; position: absolute; } &::before { top: 0; left: 0; } &::after { bottom: 0; right: 0; } } Manz ♠ Manz ::be ::af es a s i r-iz es a n i r-de h ♠
  15. [data-card] { position: relative; &::before, &::after { content: attr(data-card) attr(data-suit);

    font-size: 17px; position: absolute; } &::before { top: 4px; left: 4px; } &::after { bottom: 4px; right: 4px; } } ♠ 2♠ 2♠ núme + pa (me to ) to 4p le 4p bo m4p ri t 4p ♠
  16. @media screen and (max-width:800px){ .card::after, .item { display: none; }

    } ♠ ♠ 2♠ 2♠ sólo n a l < 800p oc mo oc mo
  17. @media screen and (max-width:800px){ ... .card { width: 38px; height:

    48px; display: flex; justify-content: center; align-items: center; } .card::before { position: static; font-size: 24px; } } 2♠ re n i mo
  18. .card:hover { box-shadow: 2px 8px 10px rgba(0,0,0, 0.5); transform: translate(-1px,

    -6px); transition: transform 0.2s ease; will-change: transform; user-select: none; cursor: pointer; } ♠ 2♠ 2♠ ♠ ♠ 2♠ 2♠ ♠ 1p 6p
  19. .card.flipped { background: repeating-linear-gradient(45deg, #11f 10%, #44f 22%); radial-gradient(#f23 80%,

    #a12 64%); conic-gradient(red,yellow,lime, aqua,blue,magenta,red); & *, &::before, &::after { display: none; } } ♠ 2♠ 2♠ ♠ 1 1 2 3 2 3