For my page layout I wanted to define a .parent element size relative to the window size:
.parent {
position: relative;
height: 100%;
width: 75%;
top: 0;
left: 12.5%;
}
Inside this .parent, I want to display an image .child element that should be rescaled to the size of of .parent (the aspect ratio of the image fits that of .parent, so this won't be a problem):
.child {
position: absolute;
max-height: 100%;
max-width: 100%;
top: 0;
left: 0;
}
HTML
<div class="parent">
<img class="child" src="/images/some_image.jpg">
<img class="child" src="/images/another_image.jpg">
</div>
However, this does not seem to work as the image is not displayed at all.
I found that the computation of the height for max height can run into problems sometimes, which would result in the element not getting displayed. This seems to be the case here. Changing either the height / width of .parent or the max-height / max-width of .child to an absolute value (e.g. 500px) gets the image displayed, but this will not work with windows of different sizes (like with different screen resolutions).
How can I work around this problem? Thank you very much in advance!