如何在不牺牲宽高比的情况下使容器中的 Gatsby 图像尽可能大?

How do I make a Gatsby image as large as possible in a container without sacrificing aspect ratio?

基本上,我想复制 object-fit: contain 行为,但使用 gatsby-plugin-image 来获得图像处理和源选择的好处。

StaticImageGatsbyImage都有一堆shared props。在您的情况下, objectFit 就是您要查找的内容。默认情况下,它采用 cover 作为值,但您可以将其更改为 contain。例如:

<StaticImage src="some/url.extension" objectFit="contain" />