2014-12-28 135 views
2

我做了一個獨特的類的div元素,然後我給這個類一個背景圖像,但它不顯示。即使我檢查元素一切都在那裏,除了關於背景圖像的一行。背景不顯示在div

我的代碼:

.godzillahatter{ 
background-image: url ("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 
background-repeat: no-repeat; 
background-attachment: fixed; 
background-position: center; } 

檢查元素:

.godzillahatter { 
background-repeat: no-repeat; 
background-attachment: fixed; 
background-position: center center; 
} 

和URL: http://honlapkell.hu/verzio1/godzilla/

我不知道是什麼問題。 div元素有內容,但我試圖給它的高度和寬度只是肯定的。我尋找解決方案,但沒有一個可行。

回答

4

歡迎SO!

更改此

background-image: url ("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

這個

background-image: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

沒有空間url(之間

友好的忠告: 每當你看到一個黃色三角形這樣在Chrome的檢查,它通常意味着你的CSS語法是錯誤的。 enter image description here

+1

如果出現錯誤,我使用不顯示黃色三角形的firefox。這是一個非常有用的信息,你讓我的生活變得更輕鬆。非常感謝你! –

1

網址後刪除多餘的空間

background-image: url ("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

應該

background-image: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 
+1

誰downvoted ?答案是非常正確的,並且是第一個回答。 –

1

刪除網址和支架之間的空間:

background-image: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 
2

測試和認證!

使用background屬性,並刪除url後的空間。

background: url("http://honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg"); 

輸出:

enter image description here

編輯:正如其他人所指出的,它會工作,如果你只是url後刪除空間。

+0

有沒有*「也」*,空間不能在那裏:) –

+0

@ RokoC.Buljan你讓我。 :) –

0

background-image的URL最好是不帶引號,也如果使用外部電源,使用雙斜線//,而不是http://

對於不太CSS代碼結合的背景屬性爲一行:

.godzillahatter 
{ 
background: url(//honlapkell.hu/verzio1/wp-content/uploads/2014/12/dalmatian-texture-1543316.jpg) no-repeat center center fixed; 
} 
+0

Downvote?請指出我的錯誤 – lolbas

+0

不是DV,但引號非常好,在'file://'環境中也會失敗(儘管在localhost/server上很好,讓瀏覽器獲得正確的協議)。 –

+0

@DominatorX我們正在談論css。 '//'不是那裏的註釋語法 – lolbas