示例工程 25-responsive-images
25-responsive-images/demo-02-object-fit/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>object-fit 与比例</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>object-fit 与比例</h1>
<p>同一张 800×600,放进不同比例的框。</p>
<div class="grid">
<figure>
<img class="cover" src="assets/product-800.svg" width="800" height="600" alt="cover" />
<figcaption>cover · 裁切填满</figcaption>
</figure>
<figure>
<img class="contain" src="assets/product-800.svg" width="800" height="600" alt="contain" />
<figcaption>contain · 完整留白</figcaption>
</figure>
<figure>
<img class="fill" src="assets/product-800.svg" width="800" height="600" alt="fill" />
<figcaption>fill · 拉伸变形</figcaption>
</figure>
</div>
</body>
</html>