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.

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="container">

  <h1>Bootstrap 3 Carousel on mobile devices</h1>

  <p>On the narrow screen the carousel is paused and the items display vertically.</p>
  <p>See also <a target="top" href="https://codepen.io/glebkema/pen/ExxKXZb">the version for Bootsrap 4</a>.</p>

  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="https://placehold.it/900x300/c69/f9c/?text=1" alt="First slide">
        <div class="carousel-caption">
          <h3>First Header</h3>
          <p>Text text text text text text text.</p>
        </div>
      </div>
      <div class="item">
        <img src="https://placehold.it/900x300/9c6/cf9/?text=2" alt="Second slide">
        <div class="carousel-caption">
          <h3>Second Header</h3>
          <p>Text text text text text text text.</p>
        </div>
      </div>
      <div class="item">
        <img src="https://placehold.it/900x300/69c/9cf/?text=3" alt="Third slide">
        <div class="carousel-caption">
          <h3>Third Header</h3>
          <p>Text text text text text text text.</p>
        </div>
      </div>
    </div>
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>
  </div>

</div>
              
            
!

CSS

              
                @media (max-width: 767px) {
  .carousel .item {
    display: block;
    margin-top: 12px;
  }
  .carousel-control, 
  .carousel-indicators {
    display: none;
  }
  
  /* Place captions under their images */
  .carousel-caption {
    color: black;
    position: static;
    text-align: left;
    text-shadow: none;
  }
  
  /* Decorations */  
  .carousel-caption h3 {
    font-weight: bold;
    margin-top: 4px;
    margin-bottom: 8px;
  }
}

/* Make the images wide and responsive. */
.carousel-inner img {
  height: auto;
  width: 100%;
}

/* Decorations */  
.carousel {
  margin-bottom: 20px;
  margin-top: 20px;
}
              
            
!

JS

              
                var isCarouselPaused = false;

$( window ).on( 'load resize', function() {
  if ( document.documentElement.clientWidth <= 767 ) {
    if ( !isCarouselPaused ) {
      $( '#myCarousel' ).carousel('pause');
      isCarouselPaused = true;
    }
  } else {
    if ( isCarouselPaused ) {
      $( '#myCarousel' ).carousel('cycle');
      isCarouselPaused = false;
    }
  };
});
              
            
!
999px

Console