Setting a max-height on a Bootstrap Carousel
<p>I'm attempting to enforce a max-height on a Bootstrap carousel. The idea is that any images which are too tall will appear with black bars to the left and right so it maintains its aspect ration without stretching the page down too far. The content being pumped into the carousel will often vary in height which is why I want to do this. </p>

<p>Currently in my Carousel the images which are around 1024x768 look fine, but if a tall piece of content is placed into it it gets cut off at the bottom, takes up the spot for the image caption underneath and still stretches the bottom out.</p>

<pre><code>.carousel {
  width: auto;
  max-height: 768px;
  overflow: hidden;
}

@media screen and (max-width: 768px) {
  .carousel {
    /* Pushes out the margins on mobile devices so it lines up with the article body. */
    margin-left: -20px !important;
    margin-right: -20px !important;
    width: inherit !important;
  }
}

.carousel:hover {
  visibility: visible;
  color: white;
  bottom: 17%;
}

.carousel .carousel &gt; .carousel-control {
  visibility: hidden;
}

.carousel .carousel-control {
  visibility: visible;
  color: white;
}

.carousel .carousel-inner {
  background-color: #000000;
}

.carousel .carousel-caption {
  position: relative;
  left: auto;
  right: auto;
  padding-bottom: 0;
}

.carousel .item img {
  margin-left: auto;
  margin-right: auto;
  min-width: 100%;
}
</code></pre>

<p>What would be the best way to enforce a height restriction on the carousel while still having the content maintain its aspect ratio, regardless of how tall it is?</p>

<p><strong>JSFiddle:</strong> <a href="https://jsfiddle.net/1exapzk8/3/" rel="noreferrer">https://jsfiddle.net/1exapzk8/3/</a> </p>