2014-09-12 52 views
6

我在我的MVC網站的以下文件夾結構:捆綁CSS的作品,但字體不加載

- 內容 - 筆記本 - CSS

- 內容 - 筆記本 - 字體

內容直接位於網站的根目錄下。在我的css文件夾我有使用相對路徑

URL(」 ../字體/ fontawesome-webfont.woff?V = 4.0.3' )

我的包目前看起來文件像:

bundles.Add(new StyleBundle("~/bundles/Content/Notebook/css").Include(
     "~/Content/Notebook/css/animate.css", 
     "~/Content/Notebook/css/font.css", 
     "~/Content/Notebook/css/font-awesome.min.css", 
     "~/Content/Notebook/css/app.css" 
)); 

此使用

@Styles.Render("~/bundles/Content/Notebook/css") 

此作品爲css文件,但字體呈現文件沒有加載,我看到它正在尋找在這裏http://localhost/MySite/bundles/Content/fonts/fontawesome-webfont.woff?v=4.0.3

我看到了,然後試圖改變我的包名稱

〜/內容/筆記本電腦/ CSS

認爲,如果我從名稱中刪除「捆綁」,但是這樣做會導致css文件無法加載,那麼它會獲得相對路徑來工作。爲什麼不加載CSS文件?如果我把「捆綁」這個詞帶回到它的名字上,它又會起作用。還有關於如何讓字體隨捆綁一起加載的想法?

+0

你可以看到這個線程關於字體不能正確渲染。 http://stackoverflow.com/questions/32692151/fonts-are-not-rendered-correctly-in-release-mode-but-is-working-on-debug-mode-i ?answertab=votes#tab-top – decodingpanda 2015-09-23 03:39:48

回答

4

當你這樣做:

url('../fonts/fontawesome-webfont.woff?v=4.0.3') 

你通過一個相對路徑指的是字體。如果你把你的CSS包放在/bundles/Content/Notebook/css它會在bundles/content/fonts看,因爲這是你的相對路徑和瀏覽器看到你的CSS文件的位置的組合。

幾個可能的選項(要麼):

  • 更改你的包路徑:

    bundles.Add(new StyleBundle("~/Content/Notebook/css") ... 
    (the reason your css files didn't load when you removed bundles was that you didn't change the name of the stylebundle) 
    

    @Styles.Render("~/Content/Notebook/css") 
    
  • 參考使用絕對路徑的字體:

    url('/Content/notebook/fonts/fontawesome-webfont.woff?v=4.0.3') 
    
+0

我嘗試了第一個選項,將StyleBundle名稱更改爲〜/ Content/Notebook/css,並使用相同的渲染器,但不加載我的CSS。然後它會在http:// localhost/MySite/Content/Notebook/css /?中查找所有內容。v = 3VfY7DPwOdVyXqP6Gz8G1MTxMp6VFbReLjeUU0eWRSU1我認爲這樣可行,但我仍然不確定爲什麼簡單地刪除單詞捆綁使它停止工作。 – Paritosh 2014-09-12 14:53:08

+0

我最終更改了css文件,將字體引用爲url('../ Content/notebook/fonts/fontawesome-webfont.woff?v = 4.0.3'),並將我的軟件包名稱單獨保存起來。儘管爲什麼當我改變軟件包名稱時,css停止工作,儘管它與我在渲染調用中使用的名稱相同。 – Paritosh 2014-09-12 17:39:37

+0

您可以看到有關字體無法正確呈現的此線程。 http://stackoverflow.com/questions/32692151/fonts-are-not-rendered-correctly-in-release-mode-but-is-working-on-debug-mode-i?answertab=votes#tab-top – decodingpanda 2015-09-23 03:40:25