只需设置heightand widthof<html>和<body>to 100%, overflowto并hidden使用,和of 元素的百分比:lefttopwidthheight
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8>
<title>Proportional resizing</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
overflow: hidden;
}
div {
position: absolute;
left: 30%;
top: 20%;
width: 40%;
height: 30%;
background-color: #ddd;
}
</style>
</head>
<body>
<div>divthing</div>
</body>
</html>
这些百分比是相对于包含块的,在这种情况下是<body>。
更新:回答另一个问题:几乎不支持背景图像的缩放。当 CSS 3background-size属性获得支持时(请参阅此表),事情会变得更容易。现在,看看这个答案(是的,这意味着:更多标记)。