Spring CSS Image Upload

I am using Spring 3.0.7 for my web application. I want to load an image from my location in a CSS file, for example:

.tag { background: transparent url(/resources/img/bg.gif) no-repeat; background-position: 0 50%; padding-left: 50px } 

I can easily load my static resource into a jsp file, as shown below, without any problems:

 <c:url value="/resources/css/main.css" /> 

My static resource handler was configured as shown below:

 <mvc:resources mapping="/resources/**" location="/web-resources/"/> 

As ealier said, I can load resources into jsp files without problems, but I cannot load an image in my CSS. Can anyone help load an image in a CSS file?

+4
source share
2 answers

If your folder tree looks something like this:

 +resources -css -main.css -img -lots_of_img.jpg 

Then the easiest url('../img/bg.gif') .

+13
source

The CSS path refers to the location of the CSS document:

 .tag { background: transparent url("resources/img/bg.gif") no-repeat; background-position: 0 50%; padding-left: 50px } 

or

 .tag { background: transparent url("../resources/img/bg.gif") no-repeat; background-position: 0 50%; padding-left: 50px } 

or based on the logic of the structure

 .tag { background: transparent url("../img/bg.gif") no-repeat; background-position: 0 50%; padding-left: 50px } 

It all depends on the structure of your catalog!

Read more about it here and here.

+1
source

Source: https://habr.com/ru/post/1414883/


All Articles