-1

I want to stretch a DIV-Container inside a div to the height of 100%. The DIV-Container i want to stretch has a image inside via

<img src="http://thisisatestforstack.com/image.png"/>

I also want to center the Image vertically afterwards. I prepared a picture which makes my wishes more clear:

enter image description here

This is my Code right now:

<div id="master">
    <div id="text" style="width: 60%; float: left;">
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.<br/>
        This is an example.
    </div>

    <div id="image" style="width: 40%; float: left;">
        <img src="http://thisisatestforstack.com/image.png"/>
    </div>
</div>
user3877230
  • 439
  • 1
  • 5
  • 18

2 Answers2

3

Using flexbox layout you can achieve that as:

Code Snippet

#master {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
}
#text {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
}
#image {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
}
.item-top {
  width: 60%;
  float: left;
  -webkit-align-self: flex-start;
  -ms-flex-item-align: start;
  align-self: flex-start;
}
<div id="master">
  <div id="text" class="item-top">
    This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
    <br/>This is an example.
  </div>

  <div id="image" style="width: 40%; float: left;">
    <img src="https://www.google.co.in/logos/doodles/2016/teachers-day-2016-india-6215218130583552-res.png" />
  </div>
</div>
vivekkupadhyay
  • 2,851
  • 1
  • 22
  • 35
0

Try vertical-align: middle; for image div.

aavrug
  • 1,849
  • 1
  • 12
  • 20