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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <section class="ad">
   <div class="athena">
      <p class="accessibility">This is an ad for x -client.</p>
      <div class="content">
         <div class="cta"></div>
         <div class="card-container">
            <a class="card" data-index-url="https://www.youtube.com/watch?v=yVqf4RxQq1E" href="https://www.youtube.com/watch?v=yVqf4RxQq1E" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
            <a class="card" data-index-url="" href="" target="_blank"></a>
         </div>
      </div>
   </div>
</section>
            
          
!

CSS

            
              // select the numbers of either 2,3,4,6,8 or 9.
$card-count: 9;
// choose any color
$card-hover-color: green;

.ad {
   margin: 0 auto;
   display: block;
   width: 1060px;
   height: 590px;
}

.athena {
   display: block;
   width: 1060px;
   height: 590px;
}

.accessibility {
   border: 0;
   clip: rect(0 0 0 0);
   height: 1px;
   margin: -1px;
   overflow: hidden;
   padding: 0;
   position: absolute;
   width: 1px;
}

.content {
   position: relative;
   width: 100%;
   height: 100%;
   cursor: pointer;
   z-index: 1;
   @media (max-width: 767px) {
      background: transparent
         url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/93572/Template-Gallery_Mobile_-180419-km.png")
         no-repeat 50% 50%/cover;
   }
   @media (min-width: 768px) {
      background: transparent
         url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/93572/Sephora_JuneBeauty_-WildcardCustom_Desktop_-180409-km.jpg")
         no-repeat 50% 50%/cover;
   }
}

.cta {
   border: none;
   height: 50%;
   width: 100%;
   top: 0;
   left: 0;
   margin: 0;
   padding: 0;
   position: absolute;
   z-index: 2;
   @media (min-width: 768px) {
      height: 100%;
      width: 50%;
   }
}

.card-container {
   right: 0;
   bottom: 0;
   height: 50%;
   position: absolute;
   width: 100%;
   z-index: 2;
   @media (min-width: 768px) {
      height: 100%;
      width: 50%;
   }
}

.card {
   transition: background-color 500ms ease;
   z-index: 3;
   &:hover {
      background: transparentize($card-hover-color, 0.75);
   }
}

// lets dynamically build hover states based on the users card count input.
// for IE11 support, we build using flexbox initially.
.card-container {
   display: flex;
   flex-wrap: wrap;
   justify-content: space-around;
   @if ($card-count == 9) {
      .card {
         flex: 0 0 33.33%;
      }
   } @else if ($card-count == 8) {
      .card {
         flex: 0 0 50%;
      }
      @for $i from 9 through 9 {
         .card:nth-child(#{$i}) {
            display: none;
         }
      }
   } @else if ($card-count == 6) {
      .card {
         flex: 0 0 50%;
      }
      @for $i from 7 through 9 {
         .card:nth-child(#{$i}) {
            display: none;
         }
      }
   } @else if ($card-count == 4) {
      .card {
         flex: 0 0 50%;
      }
      @for $i from 5 through 9 {
         .card:nth-child(#{$i}) {
            display: none;
         }
      }
   } @else if ($card-count == 3) {
      .card {
         flex: 100%;
         flex-direction: column;
      }
      @for $i from 4 through 9 {
         .card:nth-child(#{$i}) {
            display: none;
         }
      }
   } @else if ($card-count == 2) {
      .card {
         flex: 100%;
         flex-direction: column;
      }
      @for $i from 3 through 9 {
         .card:nth-child(#{$i}) {
            display: none;
         }
      }
   } @else if ($card-count <= 10 or $card-count == 7 or $card-count == 5 or $card-count == 0) {
    .card { display: none; }
  } @else {
      .card {
         display: none;
      }
   }
}

// for grid support, let this override flebox below until we drop IE11 officially
@supports (display: grid) {
  .card-container {
    display: grid;
    @if ($card-count == 9) {
      grid-template: repeat(3, 1fr) / repeat(3, 1fr);
    }
    @else if ($card-count == 8) {
      grid-template: repeat(4, 1fr) / repeat(2, 1fr);
      @for $i from 9 through 9 {
        .card:nth-child(#{$i}) { display: none; }
      }
    }
    @else if ($card-count == 6) {
      grid-template: repeat(3, 1fr) / repeat(2, 1fr);
      @for $i from 7 through 9 {
        .card:nth-child(#{$i}) { display: none; }
      }
    }
    @else if ($card-count == 4) {
      grid-template: repeat(2, 1fr) / repeat(2, 1fr);
      @for $i from 5 through 9 {
        .card:nth-child(#{$i}) { display: none; }
      }
    }
    @else if ($card-count == 3) {
      grid-template: repeat(3, 1fr) / repeat(1, 1fr);
      @for $i from 4 through 9 {
        .card:nth-child(#{$i}) { display: none; }
      }
    }
    @else if ($card-count == 2) {
      grid-template: repeat(2, 1fr) / repeat(1, 1fr);
      @for $i from 3 through 9 {
        .card:nth-child(#{$i}) { display: none; }
      }
    }
    @else if ($card-count == 1) {
      grid-template: repeat(1, 1fr) / repeat(1, 1fr);
      @for $i from 2 through 9 {
        .card:nth-child(#{$i}) { display: none; }
      }
    }
    @else if ($card-count <= 10 or $card-count == 7 or $card-count == 5 or $card-count == 0) {
      .card { display: none; }
    }
    @else {
      .card { display: none; }
    }
  }
}

            
          
!

JS

            
              var productCards = document.querySelectorAll('.card');

productCards.forEach(function(card){
  // ensure that no css hidden nodes are available in the DOM once the user selects a card count.
  var displayProp = window.getComputedStyle(card, null).getPropertyValue('display');
  if (displayProp == 'none') {
    card.remove();
    return false;
  }

  // keep main clickthrough available in the event a card has no dedicated URL.
  card.addEventListener('click', function(cardLink){
    cardLink.stopPropagation();
    if (!cardLink.target.getAttribute('data-index-url') || cardLink.target.getAttribute('data-index-url') === null) {
      ad.clickThrough();
    }
  });
});

            
          
!
999px

Console