title: Make bootstrap carousel responsive on height
body: <p>I need to customize BS carousel, to make images size responsive corectly.
  I need the carousel to adapt to the height of the active slides images initiel height.
  When the viewport is wider than the image, the image/slide should scale up, but keep ratio.
  When viewport is smaller the image should scale down but keep ratio.</p>
  
  <p>I have tried many variations but cannot find the right solution.</p>
  
  <p>I hope some css/js expert can help me out here.</p>
  
  <p>Here's my current markup:</p>
  
  <pre><code>&lt;!-- Carousel
  ================================================== --&gt;
  &lt;div id="myCarousel" class="carousel slide" data-ride="carousel" data-pause="true"&gt;
        &lt;!-- Indicators --&gt;
        &lt;ol class="carousel-indicators"&gt;
          &lt;li data-target="#myCarousel" data-slide-to="0" class="active"&gt;&lt;/li&gt;
          &lt;li data-target="#myCarousel" data-slide-to="1"&gt;&lt;/li&gt;
          &lt;li data-target="#myCarousel" data-slide-to="2"&gt;&lt;/li&gt;
        &lt;/ol&gt;
        &lt;div class="carousel-inner"&gt;
          &lt;div class="item active"&gt;&lt;!--data-src="holder.js/900x500/auto/#777:#7a7a7a/text:First slide"--&gt;
            &lt;img src="MediaContent/Images/Unika%20kobbertryk%201.jpg" alt="First slide"&gt;
            &lt;div class="container"&gt;
              &lt;div class="carousel-caption"&gt;
                &lt;h1&gt;Example headline.&lt;/h1&gt;
                &lt;p&gt;Note: If you're viewing this page via a &lt;code&gt;file://&lt;/code&gt; URL, the "next" and "previous" Glyphicon buttons on the left and right might not load/display properly due to web browser security rules.&lt;/p&gt;
                &lt;p&gt;&lt;a class="btn btn-lg btn-primary" href="#" role="button"&gt;Sign up today&lt;/a&gt;&lt;/p&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="item"&gt; &lt;!--data-src="holder.js/900x500/auto/#666:#6a6a6a/text:Second slide" --&gt;
            &lt;img src="MediaContent/Images/Unika%20kobbertryk%202.jpg" alt="Second slide"&gt;
            &lt;div class="container"&gt;
              &lt;div class="carousel-caption"&gt;
                &lt;h1&gt;Another example headline.&lt;/h1&gt;
                &lt;p&gt;Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.&lt;/p&gt;
                &lt;p&gt;&lt;a class="btn btn-lg btn-primary" href="#" role="button"&gt;Learn more&lt;/a&gt;&lt;/p&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="item"&gt;&lt;!--data-src="holder.js/900x500/auto/#555:#5a5a5a/text:Third slide"--&gt;
            &lt;img src="MediaContent/Images/Unika%20kobbertryk%203.jpg"  alt="Third slide"&gt;
            &lt;div class="container"&gt;
              &lt;div class="carousel-caption"&gt;
                &lt;h1&gt;One more for good measure.&lt;/h1&gt;
                &lt;p&gt;Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.&lt;/p&gt;
                &lt;p&gt;&lt;a class="btn btn-lg btn-primary" href="#" role="button"&gt;Browse gallery&lt;/a&gt;&lt;/p&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;a class="left carousel-control" href="#myCarousel" data-slide="prev"&gt;&lt;span class="glyphicon glyphicon-chevron-left"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;a class="right carousel-control" href="#myCarousel" data-slide="next"&gt;&lt;span class="glyphicon glyphicon-chevron-right"&gt;&lt;/span&gt;&lt;/a&gt;
      &lt;/div&gt;&lt;!-- /.carousel --&gt;
  </code></pre>
  
  <p>And heres my currently css, that does not function like desciped. This version gives me a fixed 500px height, and an image that looses aspect ratio when viewport is smaller than image width.</p>
  
  <pre><code>/* GLOBAL STYLES
  
  body {
    padding-bottom: 40px;
    color: #5a5a5a;
  }
  
  
  /* CUSTOMIZE THE NAVBAR
  -------------------------------------------------- */
  
  /* Special class on .container surrounding .navbar, used for positioning it into place. */
  .navbar-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
  }
  
  /* Flip around the padding for proper display in narrow viewports */
  .navbar-wrapper .container {
    padding-left: 0;
    padding-right: 0;
  }
  .navbar-wrapper .navbar {
    padding-left: 15px;
    padding-right: 15px;
  }
  
  
  /* CUSTOMIZE THE CAROUSEL
  -------------------------------------------------- */
  
  /* Carousel base class */
  .carousel {
    min-height: 500px;
    margin-bottom: 60px;
  }
  /* Since positioning the image, we need to help out the caption */
  .carousel-caption {
    z-index: 10;
  }
  
  /* Declare heights because of positioning of img element */
  .carousel .item {
    min-height: 500px;
    background-color: #777;
  }
  .carousel-inner &gt; .item &gt; img {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 100%;
    min-height: 500px;
  }
  
  
  
  /* MARKETING CONTENT
  -------------------------------------------------- */
  
  /* Pad the edges of the mobile views a bit */
  .marketing {
    padding-left: 15px;
    padding-right: 15px;
  }
  
  /* Center align the text within the three columns below the carousel */
  .marketing .col-lg-4 {
    text-align: center;
    margin-bottom: 20px;
  }
  .marketing h2 {
    font-weight: normal;
  }
  .marketing .col-lg-4 p {
    margin-left: 10px;
    margin-right: 10px;
  }
  
  
  /* Featurettes
  ------------------------- */
  
  .featurette-divider {
    margin: 80px 0; /* Space out the Bootstrap &lt;hr&gt; more */
  }
  
  /* Thin out the marketing headings */
  .featurette-heading {
    font-weight: 300;
    line-height: 1;
    letter-spacing: -1px;
  }
  
  
  
  /* RESPONSIVE CSS
  -------------------------------------------------- */
  
  @media (min-width: 768px) {
  
    /* Remove the edge padding needed for mobile */
    .marketing {
      padding-left: 0;
      padding-right: 0;
    }
  
    /* Navbar positioning foo */
    .navbar-wrapper {
      margin-top: 20px;
    }
    .navbar-wrapper .container {
      padding-left:  15px;
      padding-right: 15px;
    }
    .navbar-wrapper .navbar {
      padding-left:  0;
      padding-right: 0;
    }
  
    /* The navbar becomes detached from the top, so we round the corners */
    .navbar-wrapper .navbar {
      border-radius: 4px;
    }
  
    /* Bump up size of carousel content */
    .carousel-caption p {
      margin-bottom: 20px;
      font-size: 21px;
      line-height: 1.4;
    }
  
    .featurette-heading {
      font-size: 50px;
    }
  
  }
  
  @media (min-width: 992px) {
    .featurette-heading {
      margin-top: 120px;
    }
  }
  </code></pre>
  
  <p>Any help appreciated.</p>