Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                .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

    for c in ['J', 'Q', 'K']
      .card(data-card=`${c}` data-suit=`${s}`)
        span.item= c+s
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Montserrat:600");
@import url('https://fonts.googleapis.com/css?family=Fredericka+the+Great&display=swap');
@use postcss-nested;
@use postcss-for;
@use postcss-simple-vars;

:root {
  background: #38761d;
  font-family: Montserrat;
  font-weight: 600;
}

.deck {
  display: flex;
/*   justify-content:center; */
  flex-wrap: wrap;
}

.card {
  width: 125px;
  height: 200px;
  background: white;
  border-radius: 10px;
  padding: 18px 6px;

/*   display:inline-block; */
  margin: 3px;
  font-size: 52px;
}

[data-suit="♥"],
[data-suit="♦"] {
  color: red;
}

/* Cards */
[data-card="1"] {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-size: 92px;
}

[data-card="2"] {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

[data-card="3"] {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

[data-card="4"] {
  display: inline-grid;
  grid-template-rows: repeat(2, 50%);
  grid-template-columns: repeat(2, 50%);
  justify-items: center;
  align-items: center;
}

[data-card="5"] {
  display: inline-grid;
  grid-template-areas:
    "i1 . i2"
    ". i3 ."
    "i4 . i5";
  justify-items: center;
  align-items: center;

  & .item:nth-child(1) {
    grid-area: i1;
  }
  & .item:nth-child(2) {
    grid-area: i2;
  }
  & .item:nth-child(3) {
    grid-area: i3;
  }
  & .item:nth-child(4) {
    grid-area: i4;
  }
  & .item:nth-child(5) {
    grid-area: i5;
  }
}

[data-card="6"] {
  display: inline-grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  align-items: center;
}

[data-card="7"] {
  display: inline-grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  align-items: center;

  position: relative;
  & .item:nth-child(1) {
    position: absolute;
    transform: translateY(-65%);
  }
}

[data-card="8"] {
  display: inline-grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  align-items: center;

  position: relative;
  & .item:nth-child(1) {
    position: absolute;
    top: 20%;
  }

  & .item:nth-child(8) {
    position: absolute;
    bottom: 20%;
  }
}

[data-card="9"] {
  display: inline-grid;
  grid-template-rows: repeat(4, 25%);
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  align-items: center;

  position: relative;
  & .item:nth-child(1) {
    position: absolute;
  }
}

[data-card="10"] {
  display: grid;
  grid-template-rows: repeat(4, 25%);
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  align-items: center;

  position: relative;
  & .item:nth-child(1) {
    position: absolute;
    top: 15%;
  }

  & .item:nth-child(10) {
    position: absolute;
    bottom: 15%;
  }
}

/* Mirror items */

[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);
}

/* Royal cards */
[data-card="J"],
[data-card="Q"],
[data-card="K"] {
  display: inline-flex;
  justify-content: center;
  align-items: center;

  & .item {
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 30px 12px;
  }
}

/* Thumb suit */
[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;
    transform: rotate(180deg);
  }
}

/* Interactive */
.card:hover {
  box-shadow: 2px 8px 10px RGBA(0, 0, 0, 0.5);
  transform: translate(-1px, -6px);
  transition: transform 0.25s ease;
  will-change: transform;
  user-select: none;
  cursor: pointer;
}

/* Flipped card */
.card.flipped {
  background: repeating-linear-gradient(45deg, #11F 10%, #44F 22%);
  /*   background: radial-gradient(#f23 80%, #a12 64%); */
  /*   background: conic-gradient(red,yellow,lime,aqua,blue,magenta,red); */

  & *,
  &::before,
  &::after {
    display: none;
  }
}

/* Responsive */
@media screen and (max-width: 800px) {
  .card::after,
  .item {
    display: none;
  }

  .card {
    width: 38px;
    height: 48px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
  }
  .card::before {
    position: static;
    font-size: 24px;
  }
}

/* Fixes */
.card:active {
  z-index: 5;
}

/* @for $i from 4 to 7 {      
  [data-card="7"] .item:nth-child($i) {
    transform:translateY(8px) scaleY(-1);
  }
}

@for $i from 6 to 10 {      
  [data-card="10"] .item:nth-child($i) {
    color:blue;
    transform:scaleY(-1);
  }
}  */

              
            
!

JS

              
                document.querySelectorAll('.card').forEach(e => {
  e.classList.add('flipped');
  e.addEventListener('dblclick', c => e.classList.toggle('flipped'));
  e.addEventListener('wheel', c => e.style.transform = `rotate(${c.deltaY / 10}deg)`);
  displacejs(e);
});


















/*
// Equivalent to Pug Code with only <div class="deck"></div>

const deck = document.querySelector('.deck');
const suits = ['♠','♥','♦','♣'];
const royals = ['J', 'Q', 'K'];

suits.forEach(e => {
  for (let i = 1; i < 11; i++) {
    const items = `<span class="item">${e}</span>`.repeat(i);
    deck.innerHTML += `<div class="card ${e}" data-card="${i}">${items}</div>`;
  }
  royals.forEach(i => {
    const items = `<span class="item">${i+e}</span>`;
    deck.innerHTML += `<div class="card ${e}" data-card="${i}">${items}</div>`;
  });
});
*/



              
            
!
999px

Console