Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap - how to make the image being scaled down to fit the window height?

How can I make the image overflow height responsive?

The images I have sometimes have long heights which make the window scroll bar visible.

enter image description here

So I want to make these heights responsive - to make the image being scaled down to fit the window height.

enter image description here

Is it possible?

CSS,

 html, body {
    height: 100%;
    margin: 0;
    padding: 0 0;
    border: 4px solid black;
}

.container-fluid {
    height: 100%;
    display: table;
    width: 100%;
    padding-right: 0;
    padding-left: 0;
    border: 4px solid blue;
}

.row-fluid {
    height: 100%;
    display: table-cell;
    vertical-align: middle;
    width: 100%;

    border: 4px solid red;
}

.centering {
    float: none;
    margin: 0 auto;
}

HTML,

<div class="container-fluid">
    <div class="row-fluid text-center">
        <div>
            <img src="images/xxx.jpg" class="img-responsive centering">
        </div>
    </div>
</div>
like image 283
Run Avatar asked Feb 10 '16 14:02

Run


People also ask

How do I change the height of an image in Bootstrap?

Images in Bootstrap are made responsive with . img-fluid . max-width: 100%; and height: auto; are applied to the image so that it scales with the parent element.

How do I scale an image to fit the screen in HTML?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels. For example, the original image is 640×960.


1 Answers

You can use height: 100% and vertical-align: top on img and on parent element use height: 100vh

body, html {
  margin: 0;
  padding: 0;
}

div {
  display: inline-block;
  height: 100vh;
  width: 100%;
  text-align: center;
}

img {
  height: 100%;
  vertical-align: top;
}
<div>
  <img src="http://placehold.it/400x850">
</div>
like image 89
Nenad Vracar Avatar answered Oct 13 '22 05:10

Nenad Vracar