0

Is it possible to contain/limit the height of an image in a column flexbox? In this fiddle, I would like to make the image be displayed in a reduced size in order to make the title underneath it be just inside the bottom of the flex parent.

Ideally, I would like to do this with a 100% CSS solution.

Here is the fiddle: https://jsfiddle.net/brandoncc/czLjoxdu/4/

The basic CSS code is:

div {
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid green;
    width: 400px;
    height: 300px;
}
Brandon
  • 1,735
  • 2
  • 22
  • 37

3 Answers3

-1

Just add a new class

img
{
  height:50%;
}

Change the percentage as you like.

D A
  • 1,724
  • 1
  • 8
  • 19
-1

try this..

<div>
<img src="http://placehold.it/350x350" / class="img-fluid">
<p>Image title</p>
div {
border: 1px solid green;
width: 400px;
height: 300px;
position:relative

}

-1

You may add the following to keep the image from overflowing and use the max space. You can change the percentage to smaller the image. Just tweak it an see what works best for you.

img {
  height: 100%;
}
Deitsch
  • 1,610
  • 14
  • 28