title: Bootstrap carousel with fixed height: center image horizontally or vertically based on image dimensions
body: <p>I have a bootstrap carousel with a fixed height. Here is the CSS:</p>
  
  <pre><code>.carousel-custom .carousel-outer {
    position: relative;
  }
  
  
  @media(min-width: 992px){
      .carousel-custom {
        margin-top: 20px;
  
      .carousel-inner {
        height: auto;
      .item {
          height:500px;
          line-height:300px;
        }
      }
    }
  }
  
  @media(max-width: 991px){
  .carousel-custom {
        margin-top: 20px;
  
      .carousel-inner {
        height: auto;
      .item {
          height:300px;
          line-height:300px;
          text-align:center;
  
        }
      }
    }
  }
  </code></pre>
  
  <p>And here is my markup:</p>
  
  <pre><code>    &lt;div id="carousel-custom-1188" class="carousel slide carousel-custom" data-ride="carousel"&gt;
        &lt;div class="carousel-outer"&gt;
          &lt;!-- Wrapper for slides --&gt;
          &lt;div class="carousel-inner" role="listbox"&gt;
              &lt;div class="item active"&gt;
                &lt;img class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459261752/w8edcuvz1yl3uc4g4o34.jpg" alt="Jinallzupvfazqqr67nd"&gt;
                &lt;div class="carousel-caption"&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="item"&gt;
                &lt;img class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459175684/w4ueot8o49dh2fyulv0x.jpg" alt="K1yov5hpur8mgsb9r15p"&gt;
                &lt;div class="carousel-caption"&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="item"&gt;
                &lt;img class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459178926/fwlmuroj2wlz7czrsha0.jpg" alt="Lqfandhmutdkppjrl932"&gt;
                &lt;div class="carousel-caption"&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;!-- Controls --&gt;
          &lt;a class="left carousel-control" href="#carousel-custom-1188" role="button" data-slide="prev"&gt;
            &lt;span class="glyphicon glyphicon-chevron-left" aria-hidden="true"&gt;&lt;/span&gt;
            &lt;span class="sr-only"&gt;Previous&lt;/span&gt;
          &lt;/a&gt;
          &lt;a class="right carousel-control" href="#carousel-custom-1188" role="button" data-slide="next"&gt;
            &lt;span class="glyphicon glyphicon-chevron-right" aria-hidden="true"&gt;&lt;/span&gt;
            &lt;span class="sr-only"&gt;Next&lt;/span&gt;
          &lt;/a&gt;
  
          &lt;!-- Indicators --&gt;
          &lt;ol class="carousel-indicators  mCustomScrollbar"&gt;
              &lt;li data-target="#carousel-custom-1188" data-slide-to="0" class="active"&gt;
                &lt;img style="height:50px; width: 50px;" class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459268139/jinallzupvfazqqr67nd.png" alt="Jinallzupvfazqqr67nd"&gt;
              &lt;/li&gt;
              &lt;li data-target="#carousel-custom-1188" data-slide-to="1" class=""&gt;
                &lt;img style="height:50px; width: 50px;" class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459268146/k1yov5hpur8mgsb9r15p.png" alt="K1yov5hpur8mgsb9r15p"&gt;
              &lt;/li&gt;
              &lt;li data-target="#carousel-custom-1188" data-slide-to="2" class=""&gt;
                &lt;img style="height:50px; width: 50px;" class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459268157/lqfandhmutdkppjrl932.png" alt="Lqfandhmutdkppjrl932"&gt;
              &lt;/li&gt;
          &lt;/ol&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>The issue is that I have images that are very wide, others very narrow and high, and others with a good ration height/width in the same carousel. </p>
  
  <p>I'd like to have the wide images centered vertically (with a width of a 100%), high images centered horizontally (with a height of 100%) and "normal" images (with a decent ratio height/width) filling all the carousel. </p>
  
  <p>Here is what I'm trying to do (first image is an example with a very wide image, second image with a very high one, and last one has a "decent" ratio).</p>
  
  <p><a href="https://i.stack.imgur.com/cRWAt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cRWAt.png" alt="Image very wide"></a></p>
  
  <p><a href="https://i.stack.imgur.com/yOKhx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yOKhx.png" alt="Image very high"></a></p>
  
  <p><a href="https://i.stack.imgur.com/LHm1t.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/LHm1t.jpg" alt="Image with decent ration"></a></p>
  
  <p>How could I achieve this ? I've tried <a href="https://stackoverflow.com/questions/19582340/make-bootstraps-carousel-both-center-and-responsive">Make Bootstrap&#39;s Carousel both center AND responsive?</a> and other tricks found on Google but none did this. </p>