123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <section class="container">
  <h1>Using the nowrap Property on an Image Carousel</h1>
  <h2>
				Tenniel Illustrations 
				for 
				Alice in Wonderland
  </h2>
  <h3>
				by Sir John Tenniel
			  </h3>

  <div class="carousel">
    <div class="carousel-inner">
      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/hand.gif" alt="Hand">
        <figcaption>
          <span>1</span> Alice's hand grabbing at Rabbit
        </figcaption>
      </figure>
      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/rabbit.gif" alt="Rabbit">
        <figcaption>
          <span>2</span> White Rabbit checking watch
        </figcaption>
      </figure>
      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/drinkmebottle.gif" alt="Bottle">
        <figcaption>
          <span>3</span> Alice taking "Drink Me" bottle
        </figcaption>
      </figure>
      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/giantalice.gif" alt="Giant Alice">
        <figcaption>
          <span>4</span> Giant Alice watching Rabbit run away
        </figcaption>
      </figure>
      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/dodo.gif" alt="Dodo">
        <figcaption>
          <span>5</span> Dodo presenting thimble
        </figcaption>
      </figure>
      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/alicetall.gif" alt="Tall Alice">
        <figcaption>
          <span>6</span> Alice stretched tall
        </figcaption>
      </figure>

      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/caterpillar.gif" alt="Caterpillar">
        <figcaption>
          <span>7</span> Alice meets the Caterpillar
        </figcaption>
      </figure>

      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/fishandfrog.gif" alt="Fish and Frog">
        <figcaption>
          <span>8</span> Fish and Frog servants
        </figcaption>
      </figure>

      <figure>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/pigbaby.gif" alt="Pig">
        <figcaption>
          <span>9</span> Alice and pig baby
        </figcaption>
      </figure>

    </div>

  </div>
  <div class="button">
    <a href="#">Scroll</a>
  </div>
</section>

<p class="p">Demo by Antonietta Perna. <a href="http://www.sitepoint.com" target="_blank">See article</a>.</p>
            
          
!
            
              * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-size: 100%;
  line-height: 1.5;
  font-family: Verdana, Arial, sans-serif;
  margin: 0;
  padding: 0;
}

h1 {
  font-size: 2em;
  font-weight: lighter;
  font-family: Georgia, "Times New Roman", serif;
  text-align: center;
}

h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: normal;
  font-size: 1.5em;
  text-align: center;
  margin-bottom: 1em;
  white-space: pre-line;
}

h3 {
  color: #9e1620;
  text-align: center;
  margin-bottom: 1em;
}

.container {
  max-width: 100%;
  min-width: 300px;
  margin: 0 auto;
  background-color: #fff;
  padding: 1em 2em;
}

.carousel {
  overflow-x: hidden;
  outline: 2px double #cb1c29;
  width: 600px;
  padding: 0;
  padding-left: 3px;
  background: #fadbdd;
  margin: 0 auto;
}

@media screen and (min-width: 300px) and (max-width: 599px) {
  .carousel {
    width: 300px;
    padding: 0;
    padding-left: 3px;
  }
}

.carousel .carousel-inner {
  white-space: nowrap;
  position: relative;
  margin: 0;
  text-align: center;
  left: 0;
  transition: left 1s linear;
}

figure {
  display: inline-block;
  width: 194px;
  height: auto;
  margin: 0;
  padding: 6px;
  position: relative;
  text-align: center;
  background: #fadbdd;
}

figure img {
  width: 90%;
  display: block;
  height: auto;
  margin: 0 auto;
}

@media screen and (min-width: 300px) and (max-width: 599px) {
  figure {
    width: 144px;
  }
}

figure:hover img,
figure:focus img {
  outline: 1px solid #9e1620;
}

figure figcaption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  background: rgba(158, 22, 32, .8);
  color: #fff;
  padding: .5em 0;
  font-size: .8em;
  font-weight: bolder;
  font-style: italic;
  white-space: normal;
  transition: opacity .5s linear;
}

figure figcaption span {
  width: 20px;
  height: 20px;
  line-height: 16px;
  font-size: 10px;
  border: 1px solid #fff;
  border-radius: 50%;
  display: block;
  text-align: center;
  margin: 0 auto;
}

figure:hover figcaption,
figure:focus figcaption {
  opacity: 0;
}

.button {
  max-width: 50%;
  margin: 2em auto;
  padding: 0.2em 0;
  font-size: 0.9em;
  font-weight: bold;
}

.button a {
  display: block;
  background: #cb1c29;
  border-radius: 1em;
  padding: 1em;
  text-align: center;
  color: #fff;
  text-decoration: none;
  transition: background .5s linear;
}

.button a:hover,
.button a:focus {
  background: #9e1620;
}

.p {
  text-align: center;
  font-size: 13px;
  padding-top: 130px;
}
            
          
!
            
              (function($) {

  var $carousel = $('.carousel'),
    $carouselWidth = $carousel.outerWidth(true),
    $carouselInner = $('.carousel-inner'),
    $numImgs = $('.carousel figure').length,

    //get each figure element width 
    $imgWidth = parseInt($('.carousel-inner figure').css('width')),
    $winSize = $(window).width(),
    paddingLarge = 17,
    paddingSmall = 11.2,
    carouselPos = 0;

  //set initial carousel position to 0 (starting point)
  $carouselInner.css('left', carouselPos);

  //Scroll button click
  $('.button a').on('click', function(e) {

    e.preventDefault();

    //if the screen size is less than 600px, show 2 images, otherwise show 3 images
    if ($winSize <= 599) {
      carouselPos += ($imgWidth * 2 + paddingSmall);
    } else {
      carouselPos += ($imgWidth * 3 + paddingLarge);
    }

    $carouselInner.css('left', -carouselPos);

    //if the position is bigger or = to the entire width of the total images, go back to position 0 
    // that is, to the beginning of the carousel
    if (carouselPos >= parseInt($imgWidth * $numImgs)) {
      carouselPos = 0; // the position goes back to 0 and the panel slides to the beginning of the carousel
      $carouselInner.css('left', carouselPos);
    }

  });

  //Adjust some values on screen resize
  $(window).resize(function() {

    $carouselWidth = $carousel.outerWidth(true);
    $imgWidth = parseInt($('.carousel-inner figure').css('width'));
    $winSize = $(window).width();

  });

})(jQuery);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console