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 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

              
                <h1>Super Simple Slider</h1>

<h2>I am a responsive slider!<br />
  (but if you remove my 'responsive' class,<br />
  I'm a fixed-width slider.)</h2>
<div class="slider responsive" width='450' height='251'>
  <div src="https://i.imgur.com/fQ8oeSF.jpg"></div>
  <div src="https://i.imgur.com/7uQRgId.jpg"></div>
  <div src="https://i.imgur.com/cT5TSuN.jpg"></div>
</div>

<!--
<h2>I am a fixed width slider!</h2>
<div class="slider" width='450' height='251' responsive='false'>
  <div src="https://i.imgur.com/fQ8oeSF.jpg"></div>
  <div src="https://i.imgur.com/7uQRgId.jpg"></div>
  <div src="https://i.imgur.com/cT5TSuN.jpg"></div>
</div>-->
              
            
!

CSS

              
                body {
  background: #E6E6E6;
  text-align: center;
  font-family: Trebuchet MS, Helvetica, san-serif;
  color: #666;
}


/* ----- SLIDER ----- */

.slider {
  display: block;
  border: 10px solid #FFF;
  background: #FFF;
  box-shadow: 0px 0px 3px rgba(0, 0, 0, .3);
  overflow: hidden;
  position: relative;
  margin: 20px auto;
}

.slide {
  background-size: cover;
  background-position: center center;
  max-width: 100%;
  min-width: 100%;
  position: absolute;
  display: none;
}

.slide.active {
  z-index: 100;
  display: block;
}

.slide.next {
  z-index: 50;
  display: block;
}

.dots {
  position: absolute;
  z-index: 200;
  width: 100%;
  text-align: center;
  bottom: 10px;
  height: 15px;
}

.dots span {
  background: rgba(0, 0, 0, .2);
  display: inline-block;
  box-shadow: inset 0 0 2px 0 rgba(0, 0, 0, .3);
  width: 9px;
  height: 9px;
  border-radius: 9px;
  margin: 3px;
}

.dots span.active {
  background: rgba(0, 0, 0, .8);
}
              
            
!

JS

              
                //You can remove the 'responsive' class from
//the slider to make it fixed-width.
//find more stuff at http://megdal.be

//edit: fixed bug where responsive slider 
//didn't work until window resize.

$(".slider").each(function() {
  s = $(this);

  //create dots and slides
  d = $("<div class='dots'>");
  s.find("div").each(function(i, e) {
    sl = $(this);
    src = sl.attr("src");
    sl.removeAttr("src");
    sl.css("background-image", "url('" + src + "')").addClass("slide");

    if (i == 0) {
      d.append("<span class='active'>");
      sl.addClass("active");
    } else if (i == 1) {
      d.append("<span class='next'>");
      sl.addClass("next");
    } else {
      d.append("<span>");
    }
  });
  s.append(d);

  //create fading slider
  setInterval(function() {
    s.find(".slide.active").fadeOut(function() {
      s.find(".slide.active").removeClass("active");
      s.find("span.active").removeClass("active");

      c = s.find(".slide.next");
      cD = s.find("span.next");
      c.removeClass("next").addClass("active");
      cD.removeClass("next").addClass("active");

      n = c.next();
      nD = cD.next();
      if (n.is(".slide")) {
        n.addClass("next");
        nD.addClass("next");
      } else {
        n = s.find(".slide:first-child");
        n.addClass("next");
        s.find(".dots span:first-child").addClass("next");
      }
      n.fadeIn();
    });
  }, 5000);

  //create responsive or static
  if (s.hasClass("responsive")) {
    resizeMe(s);
  } else {
    s.css('width', s.attr('width')).css('height', s.attr('height'));
    s.find('div').css('width', s.attr('width')).css('height', s.attr('height'));
  }
});

$(window).resize(function() {
  $(".slider").each(function() {
    s = $(this);
    if (s.hasClass("responsive")) {
      resizeMe(s);
    }
  });
});

function resizeMe(s) {
  w = s.parent().width() - 30; //30 is the margin + border width * 2. Change this to whatever you want for more/less space around slider.
  h = w / s.attr('width') * s.attr('height')
  s.css('width', w).css('height', h);
  s.find('.slide').css('width', w).css('height', h);
}
              
            
!
999px

Console