码迷,mamicode.com
首页 > 其他好文 > 详细

图片适应屏幕居中显示,且不变形

时间:2019-01-08 15:20:12      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:css   htm   absolute   contain   适应   size   图片   col   pre   

html:

<div class=‘item‘>
    <div class = ‘container‘ />
</div>
css:

    .item {
        width: 100%;
        height: 100%;
           .container  {
              max-width: 100%;
              height: auto;
              min-height: 720px;
              position: absolute;
              left: 50%;
              top: 50%;
              transform: translate(-50%, -50%);  // 利用位移实现居中                               
              background-image: url(./img/1.png);
              background-size: 100%;
              background-repeat: no-repeat;
              background-position: center 0;
    }                                    

 

图片适应屏幕居中显示,且不变形

标签:css   htm   absolute   contain   适应   size   图片   col   pre   

原文地址:https://www.cnblogs.com/aloehui/p/10238299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!