背景图片居中显示

 1 <!html>
 2 <head>
 3 <meta charset="utf-8">
 4 <title> css3 图片等比缩放,居中显示 </title>
 5 <style>
 6 .mysec{ 
 7     width:400px;
 8     height:200px;
 9     border:solid 1px #ccc;
10     background-color:red;
11     background-image:url(image/DSCI0002.JPG); /*图片地址*/
12     background-origin:content;/*从content区域开始显示背景*/
13     background-position:50% 50%; /*图片上下左右居中*/
14     background-size:contain; /*保持图像本身的宽高比例,将图片缩放到宽度或高度正好适应定义背景的区域*/
15     background-repeat:no-repeat;/*图像不重复显示*/
16 }
17 </style>
18 </head>
19 <body>
20 <section class="mysec"></section>
21 </body>
22 </html>
原文地址:https://www.cnblogs.com/ykt8465279130/p/3443701.html