How to display portrait and landscape images alternating in the same spot?

Discussion in 'HTML & Website Design' started by Chris8080, Feb 20, 2024.

  1. #1
    Hello,

    I've got a community (built on Drupal) and members upload their content including their images.
    Some are portrait, some are landscape - could be anything from leaflets to photos.
    I have not influence over their images and simply cropping them, is destroying the UX.
    The images are currently displayed in a rectangular landscape format.

    Is there a HTML / CSS solution to this problem?
    Smartphone videos being watched on a desktop have sometimes the same video blurry in the background, visible on the left and right side.
    Maybe there is even a better approach?

    In Drupal itself the options seem to be a bit limited.

    Thanks,
    Chris
     
    Chris8080, Feb 20, 2024 IP
  2. GreenHost.Cloud

    GreenHost.Cloud Active Member

    Messages:
    471
    Likes Received:
    34
    Best Answers:
    3
    Trophy Points:
    73
    #2
    One solution to consider is using CSS to create a responsive design that resizes images based on their aspect ratio. By using a combination of CSS grid and media queries, you can adjust the image sizes dynamically to fit different screen sizes. This way, portrait and landscape images can be displayed without cropping, maintaining the original aspect ratio. Additionally, you can explore JavaScript options like a lightbox gallery plugin to provide a better user experience for viewing images on different devices.
     
    GreenHost.Cloud, Feb 22, 2024 IP
  3. Chris8080

    Chris8080 Active Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #3
    It's not about devices.
    Just the same device and different formats.
     
    Chris8080, Feb 22, 2024 IP
  4. Mark Elijah

    Mark Elijah Greenhorn

    Messages:
    145
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    18
    #4
    There's a neat CSS trick to handle this! You can set a container element with a fixed height and background color. Inside, the images will automatically resize to fit while maintaining aspect ratio. This way, portrait images won't stretch and landscape images will fill the width with black bars on top/bottom (similar to letterboxing a movie). This keeps the layout clean and avoids cropping. Let me know if you'd like the specific code!
     
    Mark Elijah, Apr 3, 2024 IP
  5. Chris8080

    Chris8080 Active Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #5
    That's a good idea - I'll give this a try, thanks.
     
    Chris8080, Apr 4, 2024 IP