2012-07-29 77 views
3

我非常感謝任何幫助。 我有一個div與background: url("../images/description_bkgrnd.jpg") repeat; display: none; 後來這個div使jQuery可見。 當url看起來像http://localhost/product-name-p35/一切正常,但當它看起來像 像http://localhost/product-name-p35/RU/瀏覽器無法加載圖像。 在螢火蟲我看到它正試圖加載http://localhost/product-name-p35/images/description_bkgrnd.jpg, 不是http://localhost/images/description_bkgrnd.jpg/ 是什麼責怪?當URL更長時,CSS背景圖片加載失敗

回答

1
url("../images/description_bkgrnd.jpg") 

這是一個相對路徑。當你在目錄http://localhost/product-name-p35/RU/,它是從http://localhost/product-name-p35/加載圖像(因爲..

一個可能的方法來解決這個問題是絕對路徑來引用圖像:

url("http://localhost/images/description_bkgrnd.jpg") 

另一種可能方法是使用

url("/images/description_bkgrnd.jpg") 

/之初使得瀏覽器發送請求到網站的根。但要確保images文件夾位於網站根目錄下,或者相應地修改URL。

參考:http://www.ibdhost.com/help/path/

+0

謝謝!我在想它。我相信它會起作用,但它有點難看。它似乎使它看起來很漂亮,我必須有這樣的網址:http:// localhost/RU/product-name-p35 – 2012-07-29 06:17:11

+1

您可以使用像路徑 'url(「/ images/description_bkgrnd.jpg」) ' 開始時的斜線使其在您網站的根目錄中查找圖像目錄。 – 2012-07-29 06:18:25

1

..意味着你要去一個級別,所以當你在RU文件夾就會去/產品名稱-P35文件夾

+0

謝謝。什麼是可能的解決方案? – 2012-07-29 06:12:18

+0

刪除..這就是它應該這樣做 – 2012-07-29 06:12:54

+0

刪除..做到了!謝謝! – 2012-07-29 06:29:07