object-fit:包含不适合 A4 大小 div 的较小元素

object-fit: contain doesnt fit an A4 size div in a smaller element

我正在尝试将 A4 尺寸 div 放入较小的元素中。我考虑过为此使用 object-fit: contain; 。当我阅读 MDN 上的文档时,它似乎非常适合我的需要。自动缩放很不错。我想我忘记了什么地方。

Try it online!

header {
  background: orange;
  height: 60px;
  width: 100%;
}

aside {
  background: lightblue;
  width: 200px;
}

main {
  background: lightgrey;
  width: 100%;
}

#wrapper {
  width: 100%;
  height: 500px;
  background: white;

}

.block {
  display:flex;
  width: 100%;
  height: 100%;
  background: grey;
}

.pdf {
  background: white;
  width: 21cm;
  height: 297mm;
  object-fit: contain;
}
<div id="wrapper">
  <header>header</header>
  <div class="block">
    <aside>aside</aside>
    <main>
      <div class="pdf"></div>
    </main>
  </div>
</div>

注意我无法使用网格。

不合适,属于正常现象。

The object-fit CSS property specifies how the contents of a replaced element, such as an <img> or <video>, should be resized to fit its container.

您的 div 不是替换元素。

Typical replaced elements are:

<iframe>
<video>
<embed>
<img>

Some elements are treated as replaced elements only in specific cases:

<option>
<audio>
<canvas>
<object>
<applet>

来源: