Is it possible to have a child <img>
wider than its parent div
, while maintaining proportional width and preserving vertical space?
Using position:absolute;
might move the image out of the normal document flow, but I want to keep the vertical space that the image occupies. Removing this space would cause content following the image to display behind it.
Check out this example fiddle.
The first image shows the desired vertical behavior. If the image is made wider horizontally, its height should increase proportionally. The second image demonstrates the desired horizontal behavior, but at the expense of losing vertical space. Negative margins were attempted, but did not produce satisfactory results.
Considering unknown image dimensions, is it feasible to achieve this effect without the use of JavaScript?