2017-10-21 106 views
1

我有一個區建立這樣的:科背景圖片顯示不出來

<section id="fullpage"> 

</section> 

html, body { 
    height:100%; 
    margin:0; 
} 

#fullpage { 
    background-image: url("sakura.png"); 
} 

我在根目錄下的sakura.png但是圖像顯示不出來,我只看到一個白色的屏幕,可能是什麼問題呢?

編輯:我必須從背景圖像中刪除引號:url(「sakura.png」);

+0

是的,它是在同一個文件夾中,背景色的工作,但圖像持續失敗 – Missy

+0

在同你有文件「sakura.png」目錄,作爲該代碼段的文件? –

+0

你的問題看起來像重複的 - https://stackoverflow.com/questions/21374534/css-background-image-not-loading。請檢查答案那裏,我認爲刪除引號可以幫助 –

回答

0

嘗試給高度段。

#fullpage { 
    height: 100px; 
    background-image: url("sakura.png"); 
} 
+0

這沒有' t爲我工作:/背景顏色工作,但我的圖像不斷失敗 – Missy

+0

這應該工作,因爲它對我來說,這是寫在外部文件的CSS,並有你的控制檯錯誤? –

-1

嘗試增加/到URL,像這樣:

#fullpage { 
    background-image: url("/sakura.png"); 
} 

也可以嘗試加入的高度/寬度的部分。

1

試試這個:

* {margin:0;padding:0;box-sizing:border-box} 
 
html, body {width:100%;height:100%} 
 

 
#fullpage { 
 
    height: 100%; 
 
    background-image: url('sakura.png'); 
 
    background-repeat: no-repeat; 
 
    background-size: contain; 
 
    background-position: center; 
 
}
<section id="fullpage"></section>

同樣是這樣的:

  • #fullpage {height:100vh}
  • html, body {width:100vw;height:100vh}#fullpage {height:100%}
0

你需要的寬度屬性添加到您的#fullpage

#fullpage { 
    width:100px; 
    height: 100px; 
    background-image: url("sakura.png"); 
}