代码示例:(标识:css_dim_height_percent)
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
  height: 100%;
}

img.one {
  height: auto;
  width: auto;
}

img.two {
  height: 50%;
  width: 50%;
}
</style>
</head>
<body>

<h1>以百分比设置元素的高度和宽度</h1>
<p>请调整浏览器窗口大小以查看效果。</p>

<p>原始图像:</p>
<img class="one" src="/static/demo/images/tulip.jpg" width="300" height="300"><br>

<p>尺寸调整后的图像(以百分比计):</p>
<img class="two" src="/static/demo/images/tulip.jpg" width="300" height="300">

</body>
</html>
运行结果: