Hopefully the title was clear enough. I'm attempting to align an image and text next to each other within a div
while adjusting the height of the container based on the image's height. I've experimented with various approaches, but haven't achieved the desired outcome. Sometimes the image spills outside the boundaries of the div
, sometimes there is a large gap between the image and text, and sometimes the text appears below the image as shown in the JSFiddle example at the end. Perhaps the solution is simpler than I realize. Here's the code after several revisions:
HTML
<div class="info">
<h2>Example</h2>
<div class="photo">
<img src="https://placeholdit.imgix.net/~text?&w=500&h=700">
</div>
<div class="desc">
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. "</p>
</div>
</div>
CSS
.info {
background-color: #FFFFFF;
margin-top: 2%;
padding: 2% 4%;
box-shadow: 0 3px 5px #808080;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.info .photo {
overflow: auto;
}
.info img {
width: 30%;
}
.info .desc {
width: 70%;
float: left;
}
JSFiddle Demo
https://jsfiddle.net/dw812685/1/
Thank you!