关于html:背景缩放

4次阅读

共计 766 个字符,预计需要花费 2 分钟才能阅读完成。

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Document</title>
<style>

/* body {background: url(./assets/airpods.png) no-repeat;
  background-size: 100% 100%;
} */
div {
  width: 500px;
  height: 500px;
  border: 2px solid red;
  background: url(./images/dog.jpg) no-repeat;
  /* background: url(./assets/airpods.png) no-repeat; */
  /* background-size: 500px 200px; */
  /* 1. 只写一个参数 必定是宽度  高度省略  这时会等比例缩放 */
  /* background-size: 500px; */
  /* 2. 外面能够跟 % 绝对与父盒子来说 */
  /* background-size: 50%; */
  /* background-size: 100% 100%; */
  /* 3. cover 要齐全笼罩 div 盒子  可能有局部背景图片显示不全 */
  /* background-size: cover; */
  /* 4. contain 高度和宽度等比例拉伸  当宽度或者高度铺满 div 盒子时 不再拉伸  可能有局部空白区域 */
  background-size: contain;
}

</style>
</head>
<body>
<div></div>
</body>
</html>

正文完
 0