簡體   English   中英

需要幫助為什么背景圖像不顯示在 div 上?

[英]Needed help why background image doesn't show up on the div?

幫助我真的不知道該怎么做,我確實查看了 W3 學校網站上關於 CSS 和 HTML 的所有內容,但沒有任何效果。 文件路徑正確,但該 div class = "mainBanner" 的背景不起作用。

 <html> <head> <style> * { background-color: black; margin: 0; padding: 0; }.mainBanner { background-image: url(/images/background.jpg); color: #ffffff; text-align: center; height: 700px; } </style> </head> <div class="container mainBanner"> <h1>Welcome to The Travellers Website</h1> <h4>You're all in one solution for perfect travels. Make memories and take step across islands you've never seen before.</h4> </div> </html> <?--Is the background image covered by the * selector when the bg color is applied. This imgae from the .mainBanner class doesnt load even the file is correct-->

假設圖像位於正確的位置,您可能會收到問題,因為您沒有設置圖像本身的高度/寬度。 您可以通過使用background-size來做到這一點

 * { background-color: black; margin: 0; padding: 0; }.mainBanner { background-image: url(https://i.imgur.com/7a4DOBA.jpg); background-size:100% 100%; color: #ffffff; text-align: center; height: 700px; }
 <html> <div class="container mainBanner"> <h1>Welcome to The Travellers Website</h1> <h4>You're all in one solution for perfect travels. Make memories and take step across islands you've never seen before.</h4> </div> </html> <?--Is the background image covered by the * selector when the bg color is applied. This imgae from the .mainBanner class doesnt load even the file is correct-->

應用 bg 顏色時,背景圖像是否被 * 選擇器覆蓋? 即使文件正確,這個來自.mainBanner class 的圖片也不會加載

由於.mainBanner*更具體,因此在 .mainBanner 下指定的.mainBanner將優先。

background: url(/images/background.jpg) center no-repeat ;

暫無
暫無

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

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