I have an image and text. When the layout is wider than the image I need the image and text to be centered, and for the text to be as wide as the image. When the layout is smaller I need the image and text to shrink.
My layout is responsive and the content is dynamic so the dimensions of the image will change.
The first part can be achieved with this: http://codepen.io/anon/pen/ZGyOmB
<div class="cont">
<div class="cont2">
<img src="http://www.vector-finder.com/site-images/too_big/fantasy_banner_vector.jpg" />
<p>Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. </p>
</div>
</div>
.cont {
text-align: center;
}
.cont2 {
display: table;
width: 1px;
margin: auto;
}
p {
display: inline-block;
}
img {
//max-width: 100%;
}
However when I set the image to have a max width of 100% so it can shrink at smaller displays, then it shrinks regardless. I know that this is happening because of the styles applied to div.cont2, but I need these styles for when the layout is wider than the image.
Is there another solution? As my image is dynamic content and its width will vary so I can't use a media query with an arbitrary break point.