示例工程 20-responsive-units
20-responsive-units/demo-02-percent-vw/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>% 与 vw</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>% 与 vw</h1>
<p>父容器固定 320px;两条都写 50%,但参照物不同。</p>
<div class="stage">
<div class="bar percent">50%</div>
<div class="bar vw">50vw</div>
</div>
<p class="hint">紫色的 50vw 以视口为准;窗口越宽,它越可能超出父容器,被这里的 overflow: hidden 裁掉。</p>
</body>
</html>