Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

GenerateBlocks – responsive image resize based on container size

  • Hello Support-Team,

    I’ve tested it on a fresh WordPress 6.5.3 installation.
    These are the changes I did:
    Theme installed: GeneratePress 3.4.0
    Modules activated: Blog and Spacing

    Plugins installed: GenerateBlocks 1.9.1, GenerateBlocks Pro 1.7.0, GP Premium 2.4.0 and Yoast Duplicate Post.
    Plugins

    GenerateBlocks Settings -> CSS PRINT METHOD -> Inline Embedding
    GenerateBlocks Settings

    Appearance Customize – Use infinite scroll
    Customizing Layout

    I would like to use a container to responsive resize the image inside it. For images in square (1.) or landscape (2.) it works, but how to do it correctly for images in portrait (4.)?
    I don’t want to set the size for the image manually each time and even if I do, the size of the container in the middle is not 50% anymore. (3.)

    responsive image resize

    responsive-image-resize

  • Hi there,

    you would need to force it with sone CSS:

    
    .gb-container .gb-block-image {
        height: 100%;
        box-sizing: border-box;
    }
    .gb-container .gb-block-image img {
        height: 100%;
        width: 100%;
        object-fit: cover;
    }
    

    Please note, that using CSS to resize images may effect the browser ability to choose an appropriate srcset image, resulting in the largest srcset image being loaded regardless

  • Hello David,

    thank you for your response. Are you sure object-fit is cover and not contain?

    cover
    image4

    contain
    image5

    Oliver

  • That depends on your expectations, more info here:

    https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit

    I assumed you wanted the image to fill the parent Container Block in both its Width and Height, and for that cover will work, but will crop the image if necessary.

  • Thank you, David.

  • You’re welcome

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.