S
S
SerDIDG2014-02-18 20:24:57
css
SerDIDG, 2014-02-18 20:24:57

How to solve the problem with image paths after @import Less?

There is a structure like this:

index.html
less /
    index.less
libs /
    common /
        docs /
            docs.html
        less /
            common.less
        img /
            some-image.png

Common.less has images with paths, like url(../img/some-image.png). And everything is fine if common.less is inserted in docs.html. But when I import common.less into index.less which is inserted into the root index.html, the images take a path like url(less/img/some-image.png).
Is it possible to somehow set a relative path so that in the root index.html, when importing common.less into index.less, the pictures have the correct paths? But also, so that nothing breaks in docs.html?
So far I see the output in variables, but I would not like to have different variables for each case.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Lopatin, 2014-02-19
@SerDIDG

We lesschave the --relative-urls option for such cases.
I less.jshave a similar option relativeUrls.

W
winbackgo, 2014-02-18
@winbackgo

Use absolute paths.
@img-path: /libs/common/img/;
background-image: url(@{img-path}some-image.png);
and in general a strange structure. It would be more correct:

css /
img /
libs /
    common /
        docs /
            docs.html
index.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question