How to align an image to the bottom of the div?

  • Trying to align an image to the bottom of the out div element using vertical-align,but this vertical-align doesn’t seem to work,the image is not moving at all.
html
<div class="row">
<div class="col-md-1">
<img src="../images/image.png" style="height: 20px; width: 20px;cursor:pointer"/>
</div>
<div class=col-md-11 >
<div style="overflow:auto;height:300px"></div>
</div>
</div>
[ad type=”banner”]
  • We are using bootstrap classes for alignments. Is there anything that can make the image div align to the bottom of the outer div?Which is taking the height of second div which is 300px;.

  • something like this should do the trick:
.parent 
{
position: relative;
height: 300px;
}
.child
{
position: absolute;
bottom: 0;
}
  • You could add those classes to the DIV and the IMG respectively.
  • It looks like the parent div will be 300px high anyway because of the height set on the child in the adjacent div. If you specify the height of the parent instead, then you can absolutely position the child relative to the size of the parent.
  • If you don’t set the parent as position:relative, then the child will be position relative to something else (like the page).
  • Vertical-align won’t work because the IMG is an inline element, and the behavior you’re expecting is table-cell dependent.
  • With inline elements, vertical alignment is relative to the line and not to the parent container, so that an image aligned with text would sit in various positions relative to a given line of text.

  • Using display: table-cell is fine, provided that you’re aware that it won’t work in IE6/7
  • To fix the space at the bottom, add vertical-align: bottom to the actual imgs:
html code
<div id="randomContainer">
<div id="imageContainer">
<img src="http://dummyimage.com/50x50/f0f/fff" alt=""/>
<img src="http://dummyimage.com/50x60/f0f/fff" alt=""/>
<im
  • There’s always the most obvious fix, which is to simply remove the whitespace in the HTML:
html code
<div>a</div>
<div>a</div>
  • To this:
html code
<div>a</div><div>a</div>
[ad type=”banner”]

  • Flexboxes can accomplish this by using align-items: flex-end; flex-direction: column; with display: flex; or display: inline-flex;
css code
div#imageContainer 
{
height: 160px;
align-items: flex-end;
display: flex;
flex-direction: column;
}

< div > with some proportions :

css code
div 
{
position relative
width: 100%;
height: 100%;
}

< img >’s with their own proportions :

css code
img 
{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: auto; /* to keep proportions */
height: auto; /* to keep proportions */
max-width: 100%; /* not to stand out from div */
max-height: 100%; /* not to stand out from div */
margin: auto auto 0; /* position to bottom and center */
}
[ad type=”banner”]

Categorized in: