I am working on a flexible layout. See this script or code below, for example: http://jsfiddle.net/jasonpalter/GBygZ/
The image has a left margin - necessary if it does not cover the entire width of its container. But when the image covers the entire width of the container, the left margin needs to be removed. We can accomplish this simply with a breakpoint, but the image itself, if it is dynamic, and we do not know what its dimensions are.
Is there an automatic way (CSS or less preferably javascript) to ensure that the indent of the image can disappear when the image spans the entire width of its container?
Hmtl
<div class="pod"> <div class="img-right"> <img src="http://placehold.it/460x220" width="460" height="220" /> </div> <h3>Lorem Ipsum</h3> <div> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p> <p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p> </div> </div>
CSS
.pod { overflow: hidden; padding: 5px; border: 1px dotted #ccc; font-family: Arial, sans-serif; font-size: 12px; line-height: 1.4; } .img-right { float: right; } .img-right img { box-sizing: border-box; padding: 0 0 0 5px; max-width: 100%; height: auto; }
source share