
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>background-size详解</title>
</head>
<body>
<script>
</script>
<style>
.demo1{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
}
.demo2{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
background-size: cover;
}
.demo3{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
background-size: contain;
}
.demo4{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
background-size: 100% 100%;
}
.demo5{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
background-size:cover;
background-position: center center;
}
.demo6{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
background-size:100% 100%;
background-origin: border-box ;
}
.demo7{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
background-size:100% 100%;
background-origin: content-box ;
}
.demo8{
width:600px;
height:300px;
padding:30px;
border:10px solid red;
background: url('list_1.png') no-repeat;
background-size:100% 100%;
background-origin: border-box ;
background-clip: content-box
}
</style>
<div class="demo1">
初始样式效果:图片按照原始大小进行展示
</div>
<div class="demo2">
background-size:cover <br>
效果:按照背景最长边进行按比例放大或缩小
</div>
<div class="demo3">
background-size:contain <br>
效果:图片按照背景最短边进行按比例放大或缩小
</div>
<div class="demo4">
background-size:100% 100% <br>
效果:宽度和高度按照百分比进行填充
</div>
<div class="demo5">
background-size:cover;<br>
background-position: center center;
</div>
<div class="demo6">
background-size:100% 100%;<br>
background-origin: border-box ;
</div>
<div class="demo7">
background-size:100% 100%;<br>
background-origin: content-box ;
</div>
<div class="demo8">
background-size:100% 100%;<br>
background-origin: border-box ;<br>
background-clip: content-box
</div>
</body>
</html>