The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Maintain child proportions when parent is scaled

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #288059
    Alex Pi

    I have a parent element that is animating its shape from landscape to portrait and vice versa.
    The parent element contains an image, which as its parent changes shape, is getting distorted.
    I want the image to maintain correct proportions, staying in the middle of the parent while being cutoff at the edges for example.

    This is similar to how an image maintains proportions using object-fit, but I can’t use that here because the parent is animated using transforms to avoid layout thrashing.

    A simplified example of my problem =>


    The only way I am aware of is to reverse scale the child at the same rate as the parent is scaled.

    Alex Pi

    I tried to do what Paulie suggested, and I found this article by Google describing the process. I updated my example Pen (, but I can’t find a way for the image to fill the parent figure.

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