背景图自适应屏幕居中显示,且不变形

邮差的信 提交于 2019-12-08 01:11:02
html:

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

    .item {
        width: 100%;
        height: 100%;
           .container  {
              max-width: 100%;
              height: auto;
              min-height: 600px; // 这里可监听屏幕变化,改变最小高度
              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;
     }
    }                                    

 

 

转载于:https://www.cnblogs.com/aloehui/p/10238299.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!