Currently working on developing an image viewer that has specific requirements to meet. Here they are:
- The content area is defined as a grid-area.
- If the image is larger than the content area, it must be contained without stretching.
- If the image is smaller than the content area, it should be centered within the content area.
- Ensure there is always a div tightly wrapping the image.
A visual representation has been sketched below to illustrate the desired behavior for both portrait (top row) and landscape (bottom row) images with the left column demonstrating the expected behavior when the image's resolution exceeds the content area.
Color coding is as follows:
- White box: Content area.
- Red box: Image.
- Blue border: Wrapping div around the image.
https://i.sstatic.net/dzHpo.png
My primary approach thus far has involved absolutely positioning the wrapping div around the image, which generally works fine except when attempting to achieve resize-to-fit behavior. This often results in breaking the tightly wrapped div.
Although I can utilize JavaScript for this task, I would prefer to primarily rely on HTML and CSS due to laying a foundation for future expansions.