Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 set background image using CSS

Tags:

css

symfony

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: Project structure

What is the correct path for Symfony to know where is the image? I have tried multiple things and nothing works for me. THX

like image 787
Abel Avatar asked May 03 '14 16:05

Abel


1 Answers

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

like image 101
Animesh Avatar answered Oct 01 '22 22:10

Animesh