簡體   English   中英

如何將背景圖像拉伸到100%的寬度

[英]How to stretch a background-image to 100% width

我正在嘗試在屏幕寬度(100%)上拉伸背景圖像,但似乎無法完成這項工作。 在這張照片中更清楚地看到我的意思: 圖片或網站也在線: 鏈接

我究竟做錯了什么?

 .footer-img { background-image: url(../assets/img/footer-splashes-01.svg); background-repeat: no-repeat; background-position: center bottom; /* width: 100%; */ background-size: 100% 100%; } .container-footer { width: 96rem; margin: 0 auto; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; text-align: right; padding-top: 25rem; } footer li { height: 8rem; list-style: none; text-decoration: none; } .social-media { padding-top: 5rem; display: flex; justify-content: space-between; } 
 <footer> <div class="footer-img"> <div class="container-footer"> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Devine</a></li> </ul> <div class="social-media"> <a href="http://www.devine.be"><img src="./assets/img/devine.png" alt="devine" width=50 height=50></a> <a href="http://www.facebook.com"><img src="./assets/img/facebook.png" alt="facebook" width=50 height=50></a> <a href="http://www.twitter.com"><img src="./assets/img/twitter.png" alt="twitter" width=50 height=50></a> </div> </div> </div> </footer> 

使用background-size: cover; 而不是background-size: 100% 100%; 到您的.footer-img

堆棧片段

 .footer-img { background-image: url(../assets/img/footer-splashes-01.svg); background-repeat: no-repeat; background-position: center bottom; /* width: 100%; */ background-size: cover; } .container-footer { width: 96rem; margin: 0 auto; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; text-align: right; padding-top: 25rem; } footer li { height: 8rem; list-style: none; text-decoration: none; } .social-media { padding-top: 5rem; display: flex; justify-content: space-between; } 
 <footer> <div class="footer-img"> <div class="container-footer"> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Devine</a></li> </ul> <div class="social-media"> <a href="http://www.devine.be"><img src="./assets/img/devine.png" alt="devine" width=50 height=50></a> <a href="http://www.facebook.com"><img src="./assets/img/facebook.png" alt="facebook" width=50 height=50></a> <a href="http://www.twitter.com"><img src="./assets/img/twitter.png" alt="twitter" width=50 height=50></a> </div> </div> </div> </footer> 

.footer-img {
background-image: url(../assets/img/footer-splashes-01.svg);
background-repeat: no-repeat;
background-position: center bottom;
width: 100%;
background-size: cover;
}

這樣就可以了。 只需將background-size替換為background-size:cover

干杯。

試試看(添加到您現有的代碼中):

.footer-img {
    background-position: center top;
    background-size: 100%;
}

您最終會得到類似以下內容的結果:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM