2014-02-26 27 views
0

如何在wordpress的css中獲取根目錄?如何在css中獲取wordpress的根目錄

我的CSS是這樣的:

#bg{ 
display: block; 
background: url('/assets/images/_userfiles/bg_1.png') no-repeat center center; 
position: fixed; 
top: 0; 
left: 0; 
width: 100%; 
height: 100%; 
} 

我因子評分,這將鏈接到WordPress文件夾的根,但它並不那麼我怎麼可能得到這個權利?

我的資產地圖位於wordpress文件夾的根部。

回答

1

您使用的CSS爲您提供了域根。

所以,如果您的域名是www.site.com你的CSS嘗試請求:

www.site.com/assets/images/_userfiles/bg_1.png在CSS時提到

文件不是像絕對路徑一樣使用,而是相對於你的CSS樣式表文件。

所以,你有你的CSS文件中:

www.site.com/wp-content/themes/mytheme/style.css

而且你必須在你的文件:

www.site.com/wp-content/themes/mytheme/assets/images/_userfiles/bg_1.png

你只需要從你的css中刪除你的第一個'/'url();

#bg 
    { 
    display: block; 
    background: url('assets/images/_userfiles/bg_1.png') no-repeat center center; 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    } 

重溫

的基本網址爲相對於你的CSS文件。

相對於一個目錄去到你的CSS文件中使用url(../path/to/file/that/is/one/directory/up/from/your/css/file);

所以,只要檢查該目錄結構你的CSS文件位於你的FTP Explorer和自己的方式找出你的資產的文件夾。

您可以使用盡可能多的../../../。如果達到最大值,瀏覽器將默認爲網站的網址,就像您使用'/'開始您的網址一樣。

+1

我已經使用了4 ../並且已經達到了正確的路徑,謝謝! –