Skip to content

Add aspect ratio selector to Cover Block #54032

Closed

Description

@henriqueiamarino

What problem does this address?

A similar issue was closed in 2020, #23092. Today, we can only edit the Minimum height of cover, but due to the current stage of Gutenberg, we can fix it consistently.

Cover block styles today
pr_cover-block

What is your proposed solution?

Add the aspect ratio selector just as we have on image blocks.

Image block styles today
pr_image-block

Activity

  1. added
    [Block] CoverAffects the Cover Block - used to display content laid over a background image
    on Aug 29, 2023
  2. added
    [Type] TaskIssues or PRs that have been broken down into an individual action to take
    [Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi
    and removed on Nov 30, 2023
  3. andrewserong commented on Dec 6, 2023

    @andrewserong
    Contributor

    @jasmussen did you have an idea in mind for how this should ideally work? From a little digging, aspect-ratio seems to both have pretty good browser support, and from hacking around in Codepen, content that extends beyond the height of the container will naturally extend the container, so it seems like it might behave similarly to minimum height in that respect (which IMO is a good way for it to behave). Basically it sounds like it'd work like "try to contain to an aspect ratio if the content will allow it, otherwise expand the container".

    If exploring controls for this, I think we should probably look at it as part of block supports, so that we could (potentially) enable it for both Cover and Group blocks at the same time, instead of tying it specifically to the Cover block. It also seems a little related to background image support, so I've linked to this issue from #54336.

    I'm currently looking into a few other tasks at the moment, but if no-one beats me to it, I'm happy to have a hack around with this idea and see what seems feasible. I imagine this issue could be one that's a fair bit more complex than it appears at first glance, but it sounds worthwhile to try to get a prototype working so we can see how challenging it might be to get working 🙂

  4. jasmussen commented on Dec 7, 2023

    @jasmussen
    Contributor

    Thanks so much for looking. Yes I was indeed hoping to use aspect-ratio, just like the Image block does:

    CSS applied to image block on the frontend

    In fact, I was hoping we could transplant more or less the exact behavior from how the aspect selector works on the Image block. Here's a GIF of the image block in the editor:

    image block

    Shown in that GIF:

    • Selecting the image block and highlighting the aspect ratio dropdown, as well as width and height, in the inspector.
    • Selecting Square (1:1) and then Wide (16:9) aspect ratios and seeing the image adjust as a result
    • Adding an explicit height to the "height" control, and showing what that has of an effect.

    Notably the last part — when you add a height, it combines with the aspect ratio, so 16:9 plus "Wide" makes for a small landscape picture. This is mainly relevant to the Cover block in that it only has a max-height control. Now if we just add the aspect ratio control and ignore the width and height controls (though if it's easier to add those to at the same time that's fine), then presumably the end result would be the same. If you apply an aspect ratio, then that property will control the height based on the width, until the max-height is reached.

    I'd agree a block supports would be great, this is indeed useful to Group as well.

  5. andrewserong commented on Dec 12, 2023

    @andrewserong
    Contributor

    I have a WIP PR exploration into this feature over in #56897. There are a few potential limitations and peculiarities with how aspect ratio works, but it's ready for playing with if folks would like to take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] CoverAffects the Cover Block - used to display content laid over a background image[Feature] Design ToolsTools that impact the appearance of blocks both to expand the number of tools and improve the experi[Type] TaskIssues or PRs that have been broken down into an individual action to take

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions