Bootstrap, how to make a fixed height responsive?

How can I create a fixed height element responsive to load 3? For example, I set the carousel height to 650 pixels. But I can not make it responsive, like images. Any idea?

CSS

#article-carousel .carousel-inner{
    height:650px;
}

HTML

<!-- Carousel items -->
<div class="carousel-inner">

   <div class="active item">
     <img src="style/image/10403889_707684359268375_7804458077651816095_o.jpg" class="img-responsive"/>
   </div>
....

enter image description here

+4
source share
5 answers

You can use css3 object-fit to resize image http://jsfiddle.net/xcoq9xxg/

img {
    height: 650px;
    width: 100%;
    object-fit: cover; // here
}

Chrome Opera. polyfill : https://github.com/schmidsi/jquery-object-fit https://github.com/anselmh/object-fit.


- css3 background-size http://jsfiddle.net/dizel3d/rwdspudv/

.image {
    height: 650px;
    background-position: center;
    background-size: cover;
}

javascript, <div> <img>:

<div class="image" style="background-image: url('my-image.jpg')"></div>
+10

. vh px.

img {
    height: 85vh;
    width: 100%;
    object-fit: cover; // here
}
+2

:

.carousel-inner > item { position: relative; overflow:hidden; }
.carousel-inner > item > .img-responsive { position: absolute; top:0; bottom:0; }

, , js ( boostrap jquery):

...
function init_carousel(){
    H = +($( window ).height()); // or $('.carousel-inner') as you want ...
    $('.img-responsive').css('height',H+'px');
}
init_carousel();
...

div , css :

.carousel-inner > item { position: relative; overflow:hidden;  }
.carousel-inner > item > .img-responsive-fix { position: absolute; top:0; bottom:0; left:0; right:0; text-align:center; padding:0; margin:0; }
.carousel-inner > item > .img-responsive { witdh:auto; }
+1
          function Screensize() {
        try {
            var height = ((screen.height * 80) / 100);
            document.getElementById('Mapbox').setAttribute("style", "display:block;height:" + height + "px; overflow:auto;");
        } 
        catch (ex)
        {  alert(ex); }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
    }
0

you will need to use the carousel control class with the media query here is just an example code to add

 @media (max-width: 800px) {
    .carousel-control{
      height:350px;
    }
 }
0
source

All Articles