代码示例:(标识:css3_background-size_contain)
<!DOCTYPE html>
<html>
<head>
<style>
.div1 {
  border: 1px solid black;
  height: 120px;
  width: 150px;
  background: url(/static/demo/images/flower.gif);
  background-repeat: no-repeat;
  background-size: contain;
}

.div2 {
  border: 1px solid black;
  height: 120px;
  width: 150px;
  background: url(/static/demo/images/flower.gif);
  background-repeat: no-repeat;
  background-size: cover;
}

.div3 {
  border: 1px solid black;
  height: 120px;
  width: 150px;
  background: url(/static/demo/images/flower.gif);
  background-repeat: no-repeat;
}
</style>
</head>
<body>

<h1>background-size 属性</h1>

<h2>background-size: contain:</h2>
<div class="div1">
<p>Lorem ipsum dolor sit amet.</p>
</div>

<h2>background-size: cover:</h2>
<div class="div2">
<p>Lorem ipsum dolor sit amet.</p>
</div>

<h2>background-size 未定义:</h2>
<div class="div3">
<p>Lorem ipsum dolor sit amet.</p>
</div>

<p>原始图像:</p>
<img src="/static/demo/images/flower.gif" alt="Flowers" width="224" height="162">

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