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

              
                <div class="cart">
  <div class="container">
    <div class="grid_12">
      <h1>Cart</h1>
    </div>
    <ul class="items">
      <li class="grid_4 item">
        <a href="#" class="btn-remove">
          <span class="icon icon-remove"></span>
        </a>
        <div class="preview">
          <ul class="images" data-images="[&quot;https://s.cdpn.io/6035/purplebike_01.jpg&quot;,&quot;https://s.cdpn.io/6035/purplebike_02.jpg&quot;,&quot;https://s.cdpn.io/6035/purplebike_03.jpg&quot;,&quot;https://s.cdpn.io/6035/purplebike_04.jpg&quot;]">
            <li><img src="https://s.cdpn.io/6035/purplebike_01.jpg" /></li>
            <li><img src="https://s.cdpn.io/6035/purplebike_02.jpg" /></li>
            <li><img src="https://s.cdpn.io/6035/purplebike_03.jpg" /></li>
            <li><img src="https://s.cdpn.io/6035/purplebike_04.jpg" /></li>
          </ul>
          <img src="https://s.cdpn.io/6035/purplebike_01.jpg" />
        </div>
        <div class="details" data-price="440">
          <h3>
            58cm Purple Miele
            <span class="right">$440</span>
          </h3>
          <p>Look at your bike. Now back to this bike . Now back to your bike. Now back to this bike. Sadly, your bike just isn't as sexy</p>
          <div class="inner_container">
            <div class="col_1of2">
              <p><span class="current_quantity">1</span> @ $440</p>
            </div> 
            <div class="col_1of2 align-right">
              <p>
                <a href="#" class="btn-quantity plus">
                  <span class="icon icon-plus"></span>
                </a>
                <a href="#" class="btn-quantity minus">
                  <span class="icon icon-minus"></span>
                </a>
              </p>
              <input type="hidden" class="quantity_field" name="quantity" value="1" data-price="440" />
            </div>          
          </div>
        </div>
      </li>
      <li class="grid_4 item">
        <a href="#" class="btn-remove">
          <span class="icon icon-remove"></span>
        </a>
        <div class="preview">
          <ul class="images" data-images="[&quot;https://s.cdpn.io/6035/bluebike_01.jpg&quot;,&quot;https://s.cdpn.io/6035/bluebike_02.jpg&quot;,&quot;https://s.cdpn.io/6035/bluebike_03.jpg&quot;,&quot;https://s.cdpn.io/6035/bluebike_04.jpg&quot;]">
            <li><img src="https://s.cdpn.io/6035/bluebike_01.jpg" /></li>
            <li><img src="https://s.cdpn.io/6035/bluebike_02.jpg" /></li>
            <li><img src="https://s.cdpn.io/6035/bluebike_03.jpg" /></li>
            <li><img src="https://s.cdpn.io/6035/bluebike_04.jpg" /></li>
          </ul>
          <img src="https://s.cdpn.io/6035/purplebike_01.jpg" />
        </div>
        <div class="details" data-price="475">
          <h3>
            47cm Blue Steve Bauer
            <span class="right">$475</span>
          </h3>
          <p>WAIT ONE MINUTE! If you're not 5'1 and under, you will probably only get half a pedal stroke in before your knees hit...</p>
          <div class="inner_container">
            <div class="col_1of2">
              <p><span class="current_quantity">1</span> @ $475</p>
            </div> 
            <div class="col_1of2 align-right">
              <p>
                <a href="#" class="btn-quantity plus">
                  <span class="icon icon-plus"></span>
                </a>
                <a href="#" class="btn-quantity minus">
                  <span class="icon icon-minus"></span>
                </a>
              </p>
              <input type="hidden" class="quantity_field" name="quantity" data-price="475" value="1" />
            </div>          
          </div>
        </div>
      </li>
    </ul>
    <div class="grid_12 summary">
      <div class="inner_container">
        <div class="col_1of2 meta-data">
          <div class="sub-total">
            <em>Sub Total: </em><span class="amount"></span>
          </div>
          <div class="taxes">
            <em>Sales Tax: </em><span class="amount">5%</span>
          </div>
          <div class="shipping">
            <em>Shipping: </em><span class="amount">$20</span>
          </div>
        </div>
        <div class="col_1of2">
          <div class="total">
            <span class="amount"></span>
          </div>
        </div>
        <div class="col_1of1">
          <a href="#" class="btn-checkout">Checkout</a>
        </div>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                @import "compass/css3";

* { box-sizing: border-box; }
img { max-width: 100%; height: auto; vertical-align: sub; }

.left { float: left; }
.right { float: right; }
.clr { clr: both; }

.align-left { text-align: left; }
.align-right { text-align: right; }
.align-center { text-align: center; } 

html { background: #f5f5f5; font-family: 'Open Sans', sans; }

.icon { 
  background: url(https://s.cdpn.io/6035/glyphicons-halflings-white.png) no-repeat; 
  display: inline-block; 
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-top: 1px;
  line-height: 14px;
  vertical-align: text-top;
  background-position: 14px 14px;
}

.icon-plus { background-position: -408px -96px; }
.icon-minus { background-position: -433px -96px; }
.icon-remove { background-position: -312px 0; }

.btn-quantity { 
  width: 22px; height: 22px; 
  border-radius: 3px; 
  text-align: center; 
  display: inline-block; 
  line-height: 25px; 
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.3); 
  transition: background-color .3s ease;
  &.plus { 
    background: #3498db; 
    &:hover { background: darken(#3498db, 10%); }
  }
  &.minus { 
    background: #e74c3c; 
    &:hover { background: darken(#e74c3c, 10%); }
  }
}

.btn-remove { 
  position: absolute;
  top: 2px; right: 2px;
  z-index: 10;
  width: 22px; height: 22px; 
  border-radius: 3px; 
  text-align: center; 
  display: inline-block; 
  line-height: 25px; 
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.3); 
  transition: background-color .3s ease; 
  background: #c0392b; 
  &:hover { background: darken(#c0392b, 10%); }
    .icon { margin-top: 2px; }
}

.btn-checkout { 
  color: #fff;
  text-decoration: none;
  margin: 20px 0 0;
  padding: 10px 0;
  border-radius: 5px; 
  text-align: center; 
  display: block; 
  line-height: 25px; 
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.3); 
  transition: background-color .3s ease; 
  background: #2ecc71; 
  &:hover { background: darken(#2ecc71, 10%); }
}

.items {  
  margin: 0;
  padding: 0;
  list-style:none;
}

.item {  
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
  margin-bottom: 20px;
  position: relative;
  img { 
    border-radius: 5px 5px 0 0; 
  }
  .preview {
    ul { 
      margin: 0; padding: 0; list-style:none;
      position: relative;
      height: 100%;
    }
    li { 
      position: absolute;
      top: 0;
      opacity: 0;
      &.active {
        opacity: 1; 
      }
    }
  }
  .details { 
    padding: 10px;
    position: relative;
    overflow: hidden;
    &:before {
      content: attr(data-price);
      position: absolute;
      font-weight: 600;
      font-size: 75px;
      color: #f8f8f8;
      right: -10px;
      top: -27px;
      z-index: 0;
    }
    h3 {
      margin: 0 0 5px 0; 
      position: relative;
      z-index: 1;
    }
    p {
        font-size: .875em;
        line-height: 1.5em;
      }
    input[type="number"] {
      width: 50px; height: 30px;
      padding: 2px;
      outline: none;
      border-radius: 5px;
      border: none;
      border: 1px solid #ccc;
    }
    
  }
}

.summary {
  padding: 20px;
  background: #fff;
  box-shadow: 0 0 5px rgba(0,0,0,.1);
  border-radius: 5px;
  margin-bottom: 20px;
  .meta-data {
    border-right: 1px solid #eee; 
  }
  .total {
    font-size: 3em;
    text-align: center;
    line-height: 65px;
  }
}

              
            
!

JS

              
                var $addQuantity = $('.btn-quantity.plus'),
    $minusQuantity = $('.btn-quantity.minus'),
    $removeItem = $('.btn-remove');

$addQuantity.on('click',function(e){
  e.preventDefault();
  var $item = $(this).parents('.item'),
      $quantityField = $item.find('.quantity_field'),
      currentQuantity = $quantityField.val(),
      nextQuantity = parseFloat(currentQuantity)+1;
  
  $item.find('.current_quantity').html(nextQuantity);
  $quantityField.val(nextQuantity);
  
  calculateTotal();
  
});

$minusQuantity.on('click',function(e){
  e.preventDefault();
  var $item = $(this).parents('.item'),
      $quantityField = $item.find('.quantity_field'),
      currentQuantity = $quantityField.val();
  var prevQuantity = (currentQuantity <= 1) ? 0 : parseFloat(currentQuantity)-1;
  
  $item.find('.current_quantity').html(prevQuantity);
  $quantityField.val(prevQuantity);
  
  calculateTotal();
  
});

$removeItem.on('click',function(){
  var $item = $(this).parents('.item');
  $item.remove();
  
  calculateTotal();
});

var calculateTotal = function(  ) {
  var newSubTotal = 0;
  $('.quantity_field').each(function(){
    var quantity = $(this).val(),
        price = $(this).data('price');
    
    newSubTotal += parseFloat(quantity*price);
    
  });
  
  $('.sub-total .amount').html('$'+newSubTotal);
  
  var withTax = newSubTotal*1.05;

  var newTotal = withTax+20;
  
  $('.total .amount').html('$'+newTotal);
  
};


/*
 * Image Slide
 * I actually had a lot more fun building this image changer function that I did the rest of the cart I think. It's a pretty straight forward. Please help me improve it if you see any issues. 
 */

var imageSlide = {
  init: function(element){
    imageSlide.$imageList = $(element);
    imageSlide.images = this.$imageList.data('images');
    imageSlide.currentSlide = 0;
    imageSlide.$imageList.each(function(){
      $(this).find('li').removeClass('active').eq(0).addClass('active');
    });
    
    imageSlide.$imageList.hover(
      function(){
        imageSlide.$imageList = $(this)
        imageSlide.start();  
      },
      function(){
        imageSlide.stop();
      });
    
  },
  changeSlide: function(){       
    imageSlide.$imageList.find('li').removeClass('active').eq(imageSlide.currentSlide).addClass('active');
    
    if(imageSlide.currentSlide >= imageSlide.images.length -1) {
      imageSlide.currentSlide = 0;
    }
    else {
      imageSlide.currentSlide++;
    }
  },
  start: function(){
    imageSlide.changeSlide();
    imageSlide.timer = setInterval(imageSlide.changeSlide,300);
  },
  stop: function() {
    clearInterval(imageSlide.timer);
    imageSlide.$imageList.find('li').removeClass('active').eq(0).addClass('active');
  }
};

imageSlide.init('.images');

calculateTotal();

              
            
!
999px

Console