2014-09-12 50 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