我有以下问题:
我尝试用 CSS 加载图片。但是他们找不到。
我的 CSS 文件:
.newsMenu {
background-image: url(../gfx/bannerSeite.png);
background-repeat: no-repeat;
background-size: 900px;
}
加载 css 的我的 TwigTemplate:
{% stylesheets
'bundles/doublebeatswebsite/css/index.css'
'bundles/doublebeatswebsite/css/jquery.mCustomScrollbar.css'
output="bundles/doublebeatswebsite/css/compiled/main.css"
filter="cssrewrite"
filter="yui_css"
%}
我的目录结构
+src
+DoubleBeats
+WebsiteBundle
+Resources
+public
+css
-index.css
-jquery*.css
+web
+bundles
+doublebeatswebsite
+css
+compiled
-main.css
-main_index.css
-main_jquery*.css
-index.css
-jquery*.css
浏览器输出;由 cssrewrite 创建
url("../../../../../bundles/doublebeatswebsite/gfx/*.png")
Die angegebene URL konnte nicht geladen werden
我已经在 css 文件中尝试了绝对路径,但也没有用(我尽量避免)
url(/bundles/.../gfx/*.png)
我也尝试过不使用 cssrewrite 和使用
background-image: url(../../gfx/bannerSeite.png);
编辑
我刚刚发现我用 {{ asset() }} 设置的图片也不起作用。以前一切正常,我不知道发生了什么变化。我现在尝试将权限设置为所有网络文件中的 777 个。 Myabe 我在配置中巧合地改变了一些东西?!你有什么想法吗?
最佳答案
您可以尝试使用 uglifycss:http://symfony.com/doc/current/cookbook/assetic/uglifyjs.html
我在尝试使用 yui_css 时遇到了麻烦,但是按照上面的说明使用 uglifycss 没有问题。
另外我相信 Yui 压缩器正在被弃用:
The YUI Compressor is going through a deprecation process. But don't worry! See How to Minify CSS/JS Files (using UglifyJS and UglifyCSS) for an alternative.
来源:http://symfony.com/doc/current/cookbook/assetic/yuicompressor.html
关于css - CSS 中 Assets 的 Symfony2 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22232519/