问题描述
我想在symfony中放置菜单的背景图片。但我不知道如何做到。
我设法做了很多事情已经,但不是从css添加背景。
这是我的项目 src
文件夹与我想要创建的背景样式:
Symfony知道图像在哪里的正确路径是什么?我试过多个东西,没有什么对我有用。
THX
您应该将图片存储在文件夹中。
src / MyBundle / Resources / public / images
和您的css
src / MyBundle / Resources / public / css
由于只有 web 文件夹可以从外部访问,因此您应该使用命令
app / console assets:install web --symlink
现在,将网络文件夹的链接创建为
web / bundles / Project_name / css
web / bundles / Project_name / images
因此,图像的相对路径将是
.header {
background-image:url(../ images / mainlogo.gif);
}
在twig中,你应该使用asset()函数来链接你的样式: / p>
< link href ={{asset('bundles / acmeweb / css / yourstylesheet.css')}} = stylesheettype =text / css/>
您可以找到完整的文档
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:What is the correct path for Symfony to know where is the image? I have tried multiple things and nothing works for me.THX
解决方案You should store your images in the bundle folder.
src/MyBundle/Resources/public/images
and your css in
src/MyBundle/Resources/public/css
since only web folder is accesible from outside you should use the command
app/console assets:install web --symlink
this will now create the links for the web folder as
web/bundles/Project_name/css web/bundles/Project_name/images
So your relative path for the image would be as
.header{ background-image: url("../images/mainlogo.gif"); }
And in twig you should use asset() function to link your styles:
<link href="{{ asset('bundles/acmeweb/css/yourstylesheet.css') }}" rel="stylesheet" type="text/css" />
you can find complete documentation here
这篇关于Symfony 2使用CSS设置背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!