背景圖自適應屏幕居中顯示,且不變形

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;      } } 
相關文章
相關標籤/搜索