E
E
Erling2016-03-08 17:49:31
css
Erling, 2016-03-08 17:49:31

How to create an image path variable and assign it to classes?

When laying out a layout in less, I often use background-image (or just background). The fact is that when transferring or creating a template, many paths change (at once for the entire project) and I want to somehow set globally and once a variable that I will substitute in background.
How is this done in LESS? I tried to do it, even looked at the documentation, but when compiling (via Prepros) I get errors.
So:
- now: background-image: url(../img/header.jpg);
- need:
@path_to_template: /template/test
background-image: url( @path_to_template /img/header.jpg);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail, 2016-03-09
Chirskiy @chirskiy_mixail

Sass is better than Less, I advise you to study it, the differences are not big, you don’t need to put {} and ; at the end
write 1 big structured tree:

.block
  font-size: 14px
  .block-head
    color: #fff

I think the essence is clear, but about the compiler, I would advise Gulp, Grunt, they are very convenient + there are a lot of goodies, including min files? css, js, as well as working with images. under the retina, etc.

L
Larisa, 2016-11-04
@loratokareva

@path-img: "/images";

background-image: url("@{path-img}/name.gif");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question