I want to put a background image for a menu in symfony. But I can't figure out how to do it.
I managed to style a lot of things already, but not to add a background from css.
This is my project src
folder with the background style that I am trying to create:
Symfony 知道图像在哪里的正确路径是什么?我尝试了多种方法,但没有一种对我有用。
谢谢
您应该将图像存储在捆绑文件夹中。
src/MyBundle/Resources/public/images
和你的CSS
src/MyBundle/Resources/public/css
因为仅web文件夹可以从外部访问,您应该使用命令
app/console assets:install web --symlink
现在这将为web文件夹为
web/bundles/Project_name/css
web/bundles/Project_name/images
所以你的图像的相对路径是
.header{
background-image: url("../images/mainlogo.gif");
}
在 twig 中,您应该使用 asset() 函数来链接您的样式:
<link href="{{ asset('bundles/acmeweb/css/yourstylesheet.css') }}" rel="stylesheet" type="text/css" />
你可以找到完整的文档here http://symfony.com/doc/current/book/templating.html#linking-to-assets
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)