3

I'm 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.

 <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>

I'm 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;.

Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72
Nikhil Bharadwaj
  • 867
  • 4
  • 24
  • 42
  • 1
    please make jsfiddle link or show your css also – Ram kumar Feb 16 '16 at 06:55
  • 2
    [duplicate question](http://stackoverflow.com/questions/6520940/html-image-bottom-alignment-inside-div-container) and here is [anotherlink](http://stackoverflow.com/questions/17934332/how-do-i-position-an-image-at-the-bottom-of-div) – Kunal Surana Feb 16 '16 at 06:58
  • Use firefox - open Firebug - check out what properties are being applied / overridden under the detailed and inherited/Computed section. Adjust in browser first and apply to code next. – Gyan Feb 16 '16 at 07:00
  • http://stackoverflow.com/questions/2603700/how-to-align-3-divs-left-center-right-inside-another-div this may help you abit – programingStudentWhaddup94 Feb 16 '16 at 07:28

2 Answers2

7

If I understand you correctly, 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.

Be sure to check the documentation for this and other questions, which is well-explained at MDN.

denmch
  • 1,446
  • 12
  • 20
5

You can use flexbox for this. Appling the parent styles to the DIV. No extra styling needed for img

.parent {
  display: flex;
  justify-content: flex-end;
  flex-direction: column;
}

Here's what you'll want to add if you don't have a taskrunner adding the prefixes for maximum compatibility.

.parent {    
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-justify-content: flex-end;
            -ms-flex-pack: end;
          justify-content: flex-end;
  -webkit-flex-direction: column;
      -ms-flex-direction: column;
          flex-direction: column; 
}

Currently 97% of the browsers used today support flex.

jer0dh
  • 384
  • 3
  • 6