html - object-fit: contain 不适合 A4 大小的 div 在较小的元素中

标签 html css scale object-fit

我正在尝试将 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>

来源:

关于html - object-fit: contain 不适合 A4 大小的 div 在较小的元素中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51234617/

相关文章:

jquery - 缩放图像以适应容器,同时使用 jquery 保持纵横比

r - scale_fill_discrete 和 scale_fill_manual - 图例选项混淆

javascript - 如何使用 jQuery 拖放段落元素

javascript - 突出显示所选菜单项不起作用

javascript - Twitter Bootstrap 选项卡 : Go to Specific Tab on Page Reload or Hyperlink

javascript - 从平移点到中心缩放图像

javascript - 单击屏幕上的任意位置时,jQuery 隐藏 Bootstrap 幻灯片菜单

html - 有没有办法清理编码、居中图像并使事情保持原样

css - 样式化原子文本编辑器

jquery - JQuery Mobile 按钮的颜色不会改变颜色